Skip to content

Commit d111074

Browse files
authored
Create number-of-good-pairs.py
1 parent c19a4e1 commit d111074

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Python/number-of-good-pairs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
import collections
5+
6+
7+
class Solution(object):
8+
def numIdenticalPairs(self, nums):
9+
"""
10+
:type nums: List[int]
11+
:rtype: int
12+
"""
13+
return sum(c*(c-1)//2 for c in collections.Counter(nums).itervalues())

0 commit comments

Comments
 (0)