File tree 1 file changed +15
-20
lines changed
1 file changed +15
-20
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
- public boolean containsNearbyAlmostDuplicate (int [] nums , int k , int t ) {
3
- TreeSet <Long > treeSet = new TreeSet <>();
4
- for (int i =0 ; i <nums .length ; i ++) {
5
- long num = nums [i ];
6
- Long floor = treeSet .floor (num + t );
7
- Long ceil = treeSet .ceiling (num - t );
8
-
9
- if (floor != null && floor >= nums [i ] ||
10
- ceil != null && ceil <= nums [i ]) {
11
- return true ;
12
- }
13
-
14
- treeSet .add (num );
15
-
16
- if (i >= k ) {
17
- treeSet .remove ((long ) nums [i - k ]);
18
- }
19
- }
20
-
21
- return false ;
2
+ public boolean containsNearbyAlmostDuplicate (int [] nums , int k , int t ) {
3
+ TreeSet <Long > set = new TreeSet <>();
4
+ for (int i = 0 ; i < nums .length ; i ++) {
5
+ long num = nums [i ];
6
+ Long floor = set .floor (num + t );
7
+ Long ceil = set .ceiling (num - t );
8
+ if ((floor != null && floor >= num ) || (ceil != null && ceil <= num )) {
9
+ return true ;
10
+ }
11
+ set .add (num );
12
+ if (i >= k ) {
13
+ set .remove ((long ) nums [i - k ]);
14
+ }
22
15
}
16
+ return false ;
17
+ }
23
18
}
You can’t perform that action at this time.
0 commit comments