# Leetcode 1512. Number of Good Pairs ## 題解 ### 哈希表 ```python! class Solution: def numIdenticalPairs(self, nums: List[int]) -> int: count = {} for num in nums: if num not in count: count[num] = 1 else: count[num] += 1 output = 0 for key in count: c = count[key] if c > 1: output += c * (c - 1) // 2 return output ```