* 滿足以下條件:
* 1.0是例外可以反覆出現 0可以通配任何字符
* 2.相同的數值不會重複出現
* 3.該數組可以是亂序的
* 當數組不含有0時滿足最大值-最小值=n(數組長度)-1
* 當數組數組含有0時.滿足最大值-最小值<n(數組長度)-1
* 所以,當最大值最大值-最小值>n(數組長度)-1時,一定不是連續相鄰數組
package datastruct.usearray;
public class JudgeAdjacent {
private static boolean judege(int a[]) {
int min=Integer.MAX_VALUE;
int max=Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
if (a[i]!=0) {
if (min>a[i]) {
min=a[i];
}
if (maxa.length-1) {
return false;
}else {
return true;
}
}
public static void main(String[] args) {
int a[]={8,5,0,10,6,7,0,0};
if (judege(a)) {
System.out.println("該數組是相鄰的!");
}else {
System.out.println("該數組不是相鄰的!");
}
}
}