Python 72ms simple


  • 0
        def findPairs(self, nums, k):
            """
            :type nums: List[int]
            :type k: int
            :rtype: int
            """
            from collections import Counter
            if k == 0:
                c = Counter(nums)
                return len(filter(lambda x:x[1]>1, c.items()))
            nums = list(set(nums))
            nums.sort()
            seen = set(nums[:1])
            c = 0
            for i in nums[1:]:
                if i-k in seen:
                    c += 1
                seen.add(i)
            return c
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.