2364. Count Number of Bad Pairs
Содержание
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