K-diff Pairs in an Array (Python 3)


  • 0
    class Solution:
        def findPairs(self, nums, k):
            if k<0:return 0
            if k==0:return len(set(list(filter(lambda x:nums.count(x)>1,nums))))
            return len(set(sorted(nums)) & set(map(lambda x:x+k,nums)))
           # you can check the blog http://yangyiqing.cn/2017/12/13/leetcode/
    

Log in to reply
 

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