We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c635b70 commit b2aa7d4Copy full SHA for b2aa7d4
src/main/java/com/fishercoder/solutions/_110.java
@@ -30,22 +30,16 @@ private int getH(TreeNode root) {
30
class Solution_2 {
31
32
public boolean isBalanced(TreeNode root) {
33
- if (root == null)
34
- return true;
35
return getH(root) != -1;
36
}
37
38
private int getH(TreeNode root) {
39
40
- return 0;
+ if (root == null) return 0;
41
int leftH = getH(root.left);
42
- if (leftH == -1)
43
- return -1;
+ if (leftH == -1) return -1;
44
int rightH = getH(root.right);
45
- if (rightH == -1)
46
47
- if (Math.abs(leftH - rightH) > 1)
48
+ if (rightH == -1) return -1;
+ if (Math.abs(leftH - rightH) > 1) return -1;
49
return Math.max(leftH, rightH) + 1;
50
51
0 commit comments