Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public boolean helper(TreeNode root, TreeNode min, TreeNode max) {
- if (root == null) return true;
- if (min != null && root.val <= min.val) return false;
- if (max != null && root.val >= max.val) return false;
- return helper(root.left, min, root) && helper(root.right, root, max);
- }
- public boolean isValidBST(TreeNode root) {
- return helper(root, null, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement