Skip to content

Commit fa0e0de

Browse files
Leetcode 219
1 parent 549751b commit fa0e0de

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Contains_Duplicate_II_219.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package leetcode;
2+
3+
class Solution219 {
4+
public boolean containsNearbyDuplicate(int[] nums, int k) {
5+
for (int i = 0; i < nums.length; i++) {
6+
for (int j = i + 1; j < nums.length; j++) {
7+
if (nums[i] == nums[j]) {
8+
if (Math.abs(i - j) <= k) {
9+
return true;
10+
}
11+
12+
}
13+
}
14+
}
15+
return false;
16+
}
17+
}
18+
19+
public class Contains_Duplicate_II_219 {
20+
21+
public static void main(String[] args) {
22+
int nums[] = { 1, 2, 3, 1, 2, 3 };
23+
int k = 2;
24+
Solution219 ns = new Solution219();
25+
System.out.println(ns.containsNearbyDuplicate(nums, k));
26+
}
27+
28+
}

0 commit comments

Comments
 (0)