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

Method checkBST

java/Chapter 4/Question4_5/Question.java:7–28  ·  view source on GitHub ↗
(TreeNode n)

Source from the content-addressed store, hash-verified

5public class Question {
6 public static Integer last_printed = null;
7 public static boolean checkBST(TreeNode n) {
8 if (n == null) {
9 return true;
10 }
11
12 // Check / recurse left
13 if (!checkBST(n.left)) {
14 return false;
15 }
16
17 // Check current
18 if (last_printed != null && n.data <= last_printed) {
19 return false;
20 }
21 last_printed = n.data;
22
23 // Check / recurse right
24 if (!checkBST(n.right)) {
25 return false;
26 }
27 return true;
28 }
29
30 public static void main(String[] args) {
31 int[] array = {Integer.MIN_VALUE, Integer.MAX_VALUE - 2, Integer.MAX_VALUE - 1, Integer.MAX_VALUE};

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected