/**
* @Description 简单题,没啥说的,就是用set记录,然后set的size就相当于滑动窗口的大小
* @Date 2022/1/15 7:43 下午
* @Author wuqichuan@zuoyebang.com
**/
class Solution {
public boolean containsNearbyDuplicate(int[] nums, int k) {
Set<Integer> set = new HashSet<Integer>();
for(int i = 0; i < nums.length; i++){
if(set.contains(nums[i])){
return true;
}
set.add(nums[i]);
if(set.size() > k){
set.remove(nums[i - k]);
}
}
return false;
}
}