My Java Solution Using In-order Traversal


  • 0
    S
    public class Solution {
        TreeNode prev = null;
        public boolean isValidBST(TreeNode root) {
            // inorder
            if (root == null) return true;
            boolean res1 = isValidBST(root.left);
            if (prev != null && prev.val >= root.val) return false;
            prev = root;
            boolean res2 = isValidBST(root.right);
            return res1 && res2;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.