Problem:
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.
Answer:
class Solution(object):
def containsNearbyDuplicate(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: bool
"""
if k==0 : return False
if k>= len(nums) and len(set(nums)) < len(nums): return True
for i in range(len(nums)-k):
if len(nums[i:i+k+1])>len(set(nums[i:i+k+1])): return True
return False