C# with min/max

  • 0
    public bool IsValidBST(TreeNode root) {
            return Recurse(root, long.MinValue, long.MaxValue);
        public bool Recurse(TreeNode root, long min, long max) {
            if (root == null) return true;
            if (root.val <= min || root.val >= max) return false;
            return Recurse(root.left, min, root.val) && Recurse(root.right, root.val, max);

Log in to reply

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