Skip to content

Commit feda788

Browse files
committed
Time: 72 ms (40.88%) | Memory: 87.7 MB (52.89%) - LeetSync
1 parent 4b48167 commit feda788

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
public:
3+
long long countBadPairs(vector<int>& nums) {
4+
unordered_map<int, int> freq;
5+
long long goodPairs = 0, n = nums.size();
6+
7+
for (int i = 0; i < n; i++) {
8+
int key = nums[i] - i;
9+
goodPairs += freq[key];
10+
freq[key]++;
11+
}
12+
13+
return (n * (n - 1)) / 2 - goodPairs;
14+
}
15+
};

0 commit comments

Comments
 (0)