5 line python solution


  • 0
    X

    ‘’‘
    class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
    mydict = {}
    for i,num in enumerate(nums):
    if (i-mydict.get(num,-k-1))<=k:
    return True
    mydict[num]=i
    return False
    ’‘’


Log in to reply
 

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