We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b1ced0a commit 3dd3aa7Copy full SHA for 3dd3aa7
219.Contains-Duplicate-II.java
@@ -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