Solution 1 - Hash Map Counting
When seeing x, it forms count[x] new pairs.
""" 1512.1 - Number of Good Pairs - Solution 1 - Counting """
from typing import List
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
cnt = {}
ans = 0
for x in nums:
ans += cnt.get(x, 0)
cnt[x] = cnt.get(x, 0) + 1
return ans