# 解题思路:用查找表(集合),保存其K个值的状态 20190302 找工作期间
class Solution(object):
def containsNearbyDuplicate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: bool
"""
if len(nums) <=1 :
return False
if k <= 0:
return False
record = set()
for i in range(len(nums)):
if nums[i] in record:
return True
else:
record.add(nums[i])
if len(record) == k+1:
record.remove(nums[i-k])
return False
# n = [1,0,1,1]
# k = 1
n = [1,2,3,1,2,3]
k = 2
s = Solution()
print s.containsNearbyDuplicate(n,k)