Python solution using dictionary


  • 0
    B
    class Solution(object):
        def findPairs(self, nums, k):
            """
            :type nums: List[int]
            :type k: int
            :rtype: int
            """
            nums.sort()
            count = []
            dict = {}
            for i in xrange(len(nums)):
                if nums[i] in dict:
                    count.append((dict[nums[i]],nums[i]))
                dict[nums[i]+k] = nums[i]
            return len(set(count))
    
    

Log in to reply
 

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