We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent de52797 commit eb97573Copy full SHA for eb97573
solution/0110.Balanced Binary Tree/Solution.java
@@ -0,0 +1,13 @@
1
+class Solution {
2
+ public boolean isBalanced(TreeNode root) {
3
+ return depth(root) != -1;
4
+ }
5
+ private int depth(TreeNode root) {
6
+ if (root == null) return 0;
7
+ int left = depth(root.left);
8
+ if (left == -1) return -1;
9
+ int right = depth(root.right);
10
+ if (right == -1 || Math.abs(left - right) > 1) return -1;
11
+ return Math.max(left, right) + 1;
12
13
+}
0 commit comments