LeetCode Contains Duplicate II

心得:思考要完整。。。

 

class Solution:
    # @param {integer[]} nums
    # @param {integer} k
    # @return {boolean}
    def containsNearbyDuplicate(self, nums, k):
        dict = {}
        for i in range(len(nums)):
            if(nums[i] in dict):
                if(i-dict[nums[i]]<=k):
                    return True
            dict[nums[i]] = i
        return False