98. Validate Binary Search Tree
阿新 • • 發佈:2017-09-29
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