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) {
2020 return false ;
2121 }
2222
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+
2336 public boolean containsNearbyAlmostDuplicate (int [] nums , int k , int t ) {
2437 TreeSet <Long > set = new TreeSet <>();
2538 for (int i = 0 ; i < nums .length ; ++i ) {
Original file line number Diff line number Diff line change 44
55public class Main {
66
7- private static final String TITLE = "" ;
7+ private static final String TITLE = "Contains Duplicate " ;
88
99 public static void main (String [] args ) {
1010 try {
You can’t perform that action at this time.
0 commit comments