Skip to content

Latest commit

 

History

History
21 lines (19 loc) · 505 Bytes

532.md

File metadata and controls

21 lines (19 loc) · 505 Bytes

532. K-diff Pairs in an Array

Solution 1 (time O(n), space O(n))

class Solution(object):
    def findPairs(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        d = collections.Counter(nums)
        ans = 0
        for key, value in d.items():
            if k == 0:
                ans += (d.get(key + k, 0) > 1)
            else:
                ans += (d.get(key + k, 0) > 0)
        return ans