This commit is contained in:
parent
351207504c
commit
fcaf05a364
1 changed files with 13 additions and 0 deletions
13
medium/count_number_of_bad_pairs.py
Normal file
13
medium/count_number_of_bad_pairs.py
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue