2364. Count Number of Bad Pairs

Обновлено: 2024-03-12
1 мин
[]

Содержание

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