(int[] nums)
| 1 | class Solution { |
| 2 | public long countBadPairs(int[] nums) { |
| 3 | long n = nums.length; |
| 4 | long goodPairs=0; |
| 5 | long totalPairs = n*(n-1)/2; |
| 6 | HashMap<Integer,Integer> map = new HashMap<>(); |
| 7 | for(int i=0;i<n;i++){ |
| 8 | int val = i - nums[i]; |
| 9 | int prevCount = map.getOrDefault(val,0); |
| 10 | goodPairs += prevCount; |
| 11 | map.put(val, map.getOrDefault(val,0)+1); |
| 12 | } |
| 13 | return totalPairs - goodPairs; |
| 14 | } |
| 15 | } |
nothing calls this directly
no outgoing calls
no test coverage detected