2364. Count Number of Bad Pairs

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2364

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