/*
思路简单的做法:一次循环找出最大最小值,然后相减,差值在2~4之间,
当有四个大小王时差也可以为0,只有5个数,可以枚举所有可能出现的情况:
1.没有0或者2,3,0,5,6
2.有一个0
3.有两个0.
4.有四个0,当四个大小王时
*/
public static boolean isContinuous(int[] numbers) {
if (null == numbers || numbers.length != 5) return false;
int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE, count = 0;
for (int i = 0; i < 5; i++) {
if (numbers[i] == 0) {
count++;
continue;
}
min = Math.min(min, numbers[i]);
max = Math.max(max, numbers[i]);
}
int temp = max - min;
//枚举所有的情况
if (temp == 4 || (temp == 4 && count == 1)) {//没有0或者2,3,0,5,6
return true;
} else if (temp == 3 && count == 1) {//有一个0:0,2,3,4,5
return true;
} else if (temp == 2 && count == 2) {//有两个0:0,0,2,3,4
return true;
} else if (temp == 0 && count == 4) {//有四个0,当四个大小王时
return true;
} else {
return false;
}
}