File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
airbnb/src/main/java/com/example
tools/src/main/java/com/example Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,19 @@ public boolean containsDuplicate(int[] nums) {
20
20
return false ;
21
21
}
22
22
23
+ public boolean containsNearbyDuplicate (int [] nums , int k ) {
24
+ HashSet <Integer > set = new HashSet <>();
25
+ for (int i = 0 ; i < nums .length ; i ++) {
26
+ if (i >= k + 1 ) {
27
+ set .remove (nums [i - k - 1 ]);
28
+ }
29
+ if (!set .add (nums [i ])) {
30
+ return true ;
31
+ }
32
+ }
33
+ return false ;
34
+ }
35
+
23
36
public boolean containsNearbyAlmostDuplicate (int [] nums , int k , int t ) {
24
37
TreeSet <Long > set = new TreeSet <>();
25
38
for (int i = 0 ; i < nums .length ; ++i ) {
Original file line number Diff line number Diff line change 4
4
5
5
public class Main {
6
6
7
- private static final String TITLE = "" ;
7
+ private static final String TITLE = "Contains Duplicate " ;
8
8
9
9
public static void main (String [] args ) {
10
10
try {
You can’t perform that action at this time.
0 commit comments