1635. Number of Good Pairs
My accepted Python solution to LeetCode problem 1635, Number of Good Pairs, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2025-12-24.
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
count = {}
result = 0
for num in nums:
if num in count:
result += count[num]
count[num] += 1
else:
count[num] = 1
return result