Skip to content
LC-1512 Easy LeetCode

1512. Number of Good Pairs

Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 90% Topics: Array, Hash Table, Math, Counting
View full problem on LeetCode
Reference solution (spoiler · python)
# Time:  O(n)
# Space: O(n)

import collections


class Solution(object):
    def numIdenticalPairs(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        return sum(c*(c-1)//2 for c in collections.Counter(nums).itervalues())

Solution from kamyu104/LeetCode-Solutions · MIT