Leetcode 1635 Solution
This article provides solution to leetcode question 1635 (number-of-good-pairs)
Access this page by simply typing in "lcs 1635" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/number-of-good-pairs
Solution
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
m = collections.defaultdict(int)
ans = 0
for num in nums:
ans += m[num]
m[num] += 1
return ans