bumpsoo 2025-02-09 07:00:02 +00:00
parent 351207504c
commit fcaf05a364

View file

@ -0,0 +1,13 @@
# https://leetcode.com/problems/count-number-of-bad-pairs
from typing import List
class Solution:
def countBadPairs(self, nums: List[int]) -> int:
result = 0
counts = {}
for i in range(len(nums)):
zero_value = nums[i] - i
counts[zero_value] = counts.get(zero_value, 0) + 1
result += (i + 1) - counts[zero_value]
return result