Skip to content

Commit a1f62c0

Browse files
Merge pull request #2108 from CodingTestStudy2/이진희
[이진희] Day30
2 parents 4e8ae6a + df8448b commit a1f62c0

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)