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++;
        }
        int right=begin;
        while(postorder[begin]>postorder[end]){
            begin++;
        }
        return begin==end && vertify(postorder,start,right-1) && vertify(postorder,right,end-1);
    }
}

posted @ 2022-03-13 22:34  Dreamer_szy  阅读(25)  评论(0)    收藏  举报