We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents b98a126 + a253845 commit ba38a33Copy full SHA for ba38a33
java/0110-balanced-binary-tree.java
@@ -25,3 +25,32 @@ public static boolean isBalanced(TreeNode root) {
25
return dfs(root).getKey();
26
}
27
28
+
29
+// Solution using the bottom up approach
30
+// TC and SC is On
31
32
+class Solution {
33
34
+ public int height(TreeNode root){
35
+ if(root == null){
36
+ return 0;
37
+ }
38
39
+ int lh = height(root.left);
40
+ int rh = height(root.right);
41
42
+ return 1 + Math.max(lh,rh);
43
44
45
+ public boolean isBalanced(TreeNode root) {
46
47
48
+ return true;
49
50
51
52
53
54
+ return Math.abs(lh - rh) <= 1 && isBalanced(root.left) && isBalanced(root.right);
55
56
+}
0 commit comments