-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIsContinuous.java
More file actions
36 lines (31 loc) · 862 Bytes
/
Copy pathIsContinuous.java
File metadata and controls
36 lines (31 loc) · 862 Bytes
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
package nowcoder;
import java.util.Arrays;
public class IsContinuous {
public static boolean isContinue(int[] numbers) {
int numOfZero = 0;
int numOfInterval = 0;
int length = numbers.length;
if (length == 0) {
return false;
}
Arrays.sort(numbers);
for (int i = 0; i < length - 1; i++) {
// 计算癞子数量
if (numbers[i] == 0) {
numOfZero++;
continue;
}
// 对子,直接返回
if (numbers[i] == numbers[i + 1]) {
return false;
}
numOfInterval += numbers[i + 1] - numbers[i] - 1;
}
if (numOfZero >= numOfInterval) {
return true;
}
return false;
}
public static void main(String[] args) {
}
}