-
Notifications
You must be signed in to change notification settings - Fork 0
/
secretcompanyentrace2.java
47 lines (38 loc) · 1.16 KB
/
secretcompanyentrace2.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
43
44
45
46
47
import java.util.Arrays;
import java.util.Comparator;
public class secretcompanyentrace2 {
public static void main(String[] args){
Integer[] nums = {}; int l, r;
nums = sort(nums);
int max_l = -1; int min = l;
for(int i = 0; i < nums.length; i++){
if(nums[i] > min){
if(nums[i] < r) {
if (nums[i] - min > max_l) {
max_l = nums[i] - min;
}
min = nums[i] + 1;
}else{
if(nums[i] == r){
if (r - min > max_l) {
max_l = r - min;
min = nums[i] + 1;
}
}else{
break;
}
}
}
}
System.out.println(max_l);
}
static Integer[] sort(Integer[] arr){
Arrays.sort(arr, new Comparator<Integer>(){
@Override
public int compare(Integer x, Integer y){
return x-y;
}
});
return arr;
}
}