1. 程式人生 > >98. Validate Binary Search Tree

98. Validate Binary Search Tree

highlight bool ack solution left oot arch pre amp

public class Solution {
    public boolean isValidBST(TreeNode root) {
        Stack<TreeNode> stack=new Stack<TreeNode>();
        
        TreeNode cur=null;
        while(root!=null||!stack.isEmpty())
        {
            while(root!=null)
            {
                stack.push(root);
                root=root.left;
            }
            root=stack.pop();
            if(cur!=null&&cur.val>=root.val)
                return false;
            cur=root;
            root=root.right;
        }
        return true;
    }
}

  

98. Validate Binary Search Tree