8 line python solution with hash


  • 2
    G

    Here's some short Python code for it.

        d = {}
        t = 0
        for i in xrange(len(nums)):
            t = nums[i]
            if not t in d or i-d[t] > k:
                d[t] = i
            else:
                return True
        return False

Log in to reply
 

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