Skip to content

Commit 3dd3aa7

Browse files
committed
feat(leetcode): add No.219
1 parent b1ced0a commit 3dd3aa7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

219.Contains-Duplicate-II.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// https://leetcode.com/problems/contains-duplicate-ii/
2+
//
3+
// algorithms
4+
// Easy (36.55%)
5+
// Total Accepted: 234,075
6+
// Total Submissions: 640,395
7+
8+
9+
class Solution {
10+
public boolean containsNearbyDuplicate(int[] nums, int k) {
11+
HashMap<Integer, Integer> map = new HashMap<>();
12+
int len = nums.length;
13+
14+
for (int i = 0; i < len; i++) {
15+
if (map.containsKey(nums[i]) && i - map.get(nums[i]) <= k) {
16+
return true;
17+
}
18+
map.put(nums[i], i);
19+
}
20+
21+
return false;
22+
}
23+
}

0 commit comments

Comments
 (0)