MCPcopy Create free account
hub / github.com/careercup/ctci / checkBST

Method checkBST

java/Chapter 4/Question4_5/QuestionB.java:7–19  ·  view source on GitHub ↗
(TreeNode n, Integer min, Integer max)

Source from the content-addressed store, hash-verified

5
6public 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);

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected