From 726d664db7f293dd97fc1a1c359d57f2cbdc9ffb Mon Sep 17 00:00:00 2001 From: Jestine Paul Date: Sat, 24 Oct 2015 20:43:17 +0800 Subject: [PATCH] Simplify logic --- java/Chapter 4/Question4_5/QuestionB.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/java/Chapter 4/Question4_5/QuestionB.java b/java/Chapter 4/Question4_5/QuestionB.java index 1fe88b75..8dd1d0e3 100644 --- a/java/Chapter 4/Question4_5/QuestionB.java +++ b/java/Chapter 4/Question4_5/QuestionB.java @@ -11,11 +11,7 @@ public static boolean checkBST(TreeNode n, Integer min, Integer max) { if ((min != null && n.data <= min) || (max != null && n.data > max)) { return false; } - if (!checkBST(n.left, min, n.data) || - !checkBST(n.right, n.data, max)) { - return false; - } - return true; + return checkBST(n.left, min, n.data) && checkBST(n.right, n.data, max); } public static boolean checkBST(TreeNode n) {