zoukankan      html  css  js  c++  java
  • 剑指offer24:判断一个二叉树的后序遍历序列是否为二叉搜索树的后序遍历序列

    public static boolean isBSTSequence(int[] s,int l, int r) {
            if (s == null || r <= 0)
                return false;
            int n = r;
            int root = s[n - 1];
            int i = 0;
            for (; i < n - 1; i++) {
                if (s[i] > root)
                    break;
            }
            int j = i;
            for (; j < n - 1; j++) {
                if (s[j] < root)
                    return false;
            }
    
            boolean left = true;
            if (i > 0)
                left = isBSTSequence(s, l , i);
    
            boolean right = true;
            if(i<n-1)
                right = isBSTSequence(s, i,r-1);
            
            return (left&&right);
        }
        public static boolean isBSTSequenceJudge(int[] s) {
            if(s==null) return false;
            return isBSTSequence(s,0,s.length);
        }
  • 相关阅读:
    Repeatable Read
    Read Committed
    Read Uncommitted
    sql 事务
    实用sql语句
    管理mysql
    mysql
    sql delete语句
    sql update语句
    sql INSERT语句
  • 原文地址:https://www.cnblogs.com/todayjust/p/5421860.html
Copyright © 2011-2022 走看看