Solve without loops (Spend 48 ms in Python 3)


  • 1
    J

    2018/4/12
    Your runtime beats 100.00 % of python3 submissions.
    Runtime: 48 ms

    class Solution:
        def findPairs(self, nums, k):
            if k < 0:
                return 0
            elif k == 0:
                return len(set([i for i in nums if nums.count(i)>1]))
            else:
                nums = list(set(nums))
                x = [i-k for i in nums] + nums
                return len(x)-len(set(x))
    

Log in to reply
 

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