Leetcode 1635 Solution

This article provides solution to leetcode question 1635 (number-of-good-pairs)

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