Advertisement
aero2146

Validate Binary Search Tree

Jan 27th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. class Solution {
  2.     public boolean helper(TreeNode root, TreeNode min, TreeNode max) {
  3.         if (root == null) return true;
  4.         if (min != null && root.val <= min.val) return false;
  5.         if (max != null && root.val >= max.val) return false;
  6.         return helper(root.left, min, root) && helper(root.right, root, max);
  7.     }
  8.     public boolean isValidBST(TreeNode root) {
  9.         return helper(root, null, null);
  10.     }
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement