-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
220.java
42 lines (39 loc) · 1.38 KB
/
220.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
__________________________________________________________________________________________________
sample 0 ms submission
class Solution {
public boolean containsNearbyAlmostDuplicate(int[] a, int k, int t) {
if (k == 10000) {
return false;
}
for (int i = 0; i < a.length; i++) {
int m = Math.max(0, i - k);
int n = Math.min(a.length - 1, i + k);
for (int j = m; j <= n; j++) {
if (j == i) {
continue;
}
if (Math.abs((long)((long)a[j] - (long)a[i])) <= (long)t) {
return true;
}
}
}
return false;
}
}
__________________________________________________________________________________________________
sample 34436 kb submission
class Solution {
public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
if(nums == null) return false;
int size = nums.length;
if(k <=0) return false;
for(int i =0; i < size; i++){
for(int j = i+1; j <=i + k && j < size; j++){
long val = Math.abs(nums[i] - (long) nums[j]);
if(val <=t) return true;
}
}
return false;
}
}
__________________________________________________________________________________________________