1. 程式人生 > 其它 >leetcode 0405 檢查二叉搜尋樹

leetcode 0405 檢查二叉搜尋樹

技術標籤:leetcodeleetcodejava

Integer res = null;
    boolean flag =true;
    public boolean isValidBST(TreeNode root) {
        if (root == null) return true;
        isValidBST(root.left);
        if (res == null) res = root.val;
        else if (root.val <= res) flag = false;
        else {
            res =
root.val; } isValidBST(root.right); return flag; }