Skip to content

Commit df8448b

Browse files
committed
219. Contains Duplicate II
1 parent 26fbaf0 commit df8448b

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public boolean containsNearbyDuplicate(int[] nums, int k) {
3+
//100000
4+
5+
Set<Integer>set = new HashSet<>();
6+
7+
for(int i=0; i<nums.length; i++) {
8+
if(set.contains(nums[i])) return true;
9+
10+
set.add(nums[i]);
11+
12+
if(set.size() > k) {
13+
set.remove(nums[i-k]);
14+
}
15+
}
16+
17+
return false;
18+
}
19+
}

0 commit comments

Comments
 (0)