(TreeNode n, Integer min, Integer max)
| 5 | |
| 6 | public class QuestionB { |
| 7 | public static boolean checkBST(TreeNode n, Integer min, Integer max) { |
| 8 | if (n == null) { |
| 9 | return true; |
| 10 | } |
| 11 | if ((min != null && n.data <= min) || (max != null && n.data > max)) { |
| 12 | return false; |
| 13 | } |
| 14 | if (!checkBST(n.left, min, n.data) || |
| 15 | !checkBST(n.right, n.data, max)) { |
| 16 | return false; |
| 17 | } |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | public static boolean checkBST(TreeNode n) { |
| 22 | return checkBST(n, null, null); |