public boolean VerifySquenceOfBST(int[] sequence) {
if (sequence==null||sequence.length==0) {
return false;
}
return isPos(sequence, 0, sequence.length-1);
}
public boolean isPos(int[] ary,int start,int end) {
if (start>end) {
return true;
}
int index = end-1;
while (index>start&&ary[index]>ary[end]) {
index--;
}
for (int i = start; i < index; i++) {
if (ary[i]>ary[end]) {
return false;
}
}
return isPos(ary, start, index)&&isPos(ary, index+1, end-1);
}
网友评论