菜鸡代码
二叉搜索树的后序遍历序列
http://www.nowcoder.com/questionTerminal/a861533d45854474ac791d90e447bafd
后序遍历,顺序为左子树,右子树,根节点;
二叉搜索树的大小排序为左<根<右
根节点一定在最后,根据左字数小于根节点,右子树大于根节点的特点,将左右子树找出,然后重复进行上述操作
public class Solution {
public boolean VerifySquenceOfBST(int [] sequence) {
if(sequence==null)return false;
if(sequence.length==0)return false;
return help(sequence, 0, sequence.length-1);
}
public boolean help(int [] sequence, int start, int end) {
if(end&lt;=start)return true;
int temp = sequence[end];
boolean flag = false;
int key=start;
for(int i=start;i&lt;end;i++){
if(!flag&amp;&amp;sequence[i]&gt;temp){
key = i;
flag = true;
}
if(flag&amp;&amp;sequence[i]&lt;temp)return false;
}
return help(sequence, start, key-1)&amp;&amp;help(sequence, key, end-1);
}
}