1. 程式人生 > >python leetcode 219. Contains Duplicate II

python leetcode 219. Contains Duplicate II

class Solution:
    def containsNearbyDuplicate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: bool
        """
        mydict={}
        for i in range(len(nums)):
            n=nums[i]
            if n in mydict:
                if i-mydict[n]<=
k: return True else: mydict[n]=i else: mydict[n]=i return False