题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后续遍历结果,如果是则返回true,不是返回false,假设输入的数组的任意两个数字都不相同
思路:递归
public class VerifySequenceOfBST {
public static boolean verifySequenceOfBST(int[] source,int start,int end){
if(source==null || source.length==0 || start<0 || end<0)
return false;
if(start>=end)
return true;
int base = source[end];
int i = start;
for(;i<=end;i++){
if(source[i]>base)
break;
}
if(i==end+1)
return verifySequenceOfBST(source, start, i-2);
else{
int j = i;
for(;j<=end;j++){
if(source[j]