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

Method isBalanced

java/Chapter 4/Question4_1/QuestionBrute.java:15–26  ·  view source on GitHub ↗
(TreeNode root)

Source from the content-addressed store, hash-verified

13 }
14
15 public static boolean isBalanced(TreeNode root) {
16 if (root == null) {
17 return true;
18 }
19 int heightDiff = getHeight(root.left) - getHeight(root.right);
20 if (Math.abs(heightDiff) > 1) {
21 return false;
22 }
23 else {
24 return isBalanced(root.left) && isBalanced(root.right);
25 }
26 }
27
28 public static void main(String[] args) {
29 // Create balanced tree

Callers 1

mainMethod · 0.95

Calls 2

getHeightMethod · 0.95
absMethod · 0.80

Tested by

no test coverage detected