2364. Count Number of Bad Pairs
On This Page
class Solution:
def countBadPairs(self, nums: List[int]) -> int:
cnt = Counter()
res = 0
for i, x in enumerate(nums):
res += i - cnt[i - x]
cnt[i - x] += 1
return res