Leetcode:剑指 Offer 33. 二叉搜索树的后序遍历序列


这题主要是利用二叉法递归划分左右子树,有时间重做一下!

class Solution {
    public boolean verifyPostorder(int[] postorder) {
        int root=postorder.length-1;
        return vertify(postorder,0,root);
    }

    public boolean vertify(int[] postorder,int start,int end){
        if(start>=end){
            return true;
        }
        int begin=start;
        while(postorder[begin]postorder[end]){
            begin++;
        }
        return begin==end && vertify(postorder,start,right-1) && vertify(postorder,right,end-1);
    }
}