blob: ea05f1b2e487a303b0ec396ac89fbe2dda00d9e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# 1512. Number of Good Pairs
"""
given an array of integers 'nums', return the number of good pairs. a pair
'(i, j)' is called good if 'nums[i] == nums[j]' and 'i < j'
"""
class Solution(object):
def numIdenticalPairs(self, nums):
cnt = 0
for i in range(len(nums)):
for j in range(i + 1, len(nums)):
if nums[i] == nums[j]:
cnt += 1
return cnt
if __name__ == "__main__":
obj = Solution()
print(obj.numIdenticalPairs([1,2,3,1,1,3])) # expect: 4
print(obj.numIdenticalPairs([1,1,1,1])) # expect: 6
print(obj.numIdenticalPairs([1,2,3])) # expect: 0
|