2176. Count Equal and Divisible Pairs in an Array 發表於 2023-02-13 | 分類於 leetcode problemsolution12345678910111213class Solution {public: int countPairs(vector<int>& nums, int k) { // brute force => time complexity O(n^2) int n = nums.size(), count = 0; for(int i=0;i<n-1;++i){ for(int j=i+1;j<n;++j){ if(nums[i]==nums[j] && (i*j)%k==0) count++; } } return count; }}; analysis time complexity O(n) speed complexity O(1)