码迷,mamicode.com
首页 > 其他好文 > 详细

98. Validate Binary Search Tree

时间:2017-09-29 10:06:11      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:date   public   new   turn   false   empty   return   treenode   sea   

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

标签:date   public   new   turn   false   empty   return   treenode   sea   

原文地址:http://www.cnblogs.com/asuran/p/7609352.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!