Beat 100% Python


  • 1
    S
    class Solution(object):
        def containsNearbyDuplicate(self, nums, k):
            """
            :type nums: List[int]
            :type k: int
            :rtype: bool
            """
            if len(list(set(nums))) == len(nums):return False
            for i in range(len(nums)):
                for j in range(i+1,len(nums)):
                    if nums[i]==nums[j] and abs(i-j)<=k:
                        return True
                    if abs(i-j)>k:
                        j = len(nums)
    
            return False
    

  • 0
    V

    @SmallerWhale said in Beat 100% Python:

    if abs(i-j)>k:
    j = len(nums)

    What is it doing? If it's needed in the code?


Log in to reply
 

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