Skip to content

Commit b2aa7d4

Browse files
edit 110
1 parent c635b70 commit b2aa7d4

File tree

1 file changed

+4
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-10
lines changed

src/main/java/com/fishercoder/solutions/_110.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,16 @@ private int getH(TreeNode root) {
3030
class Solution_2 {
3131

3232
public boolean isBalanced(TreeNode root) {
33-
if (root == null)
34-
return true;
3533
return getH(root) != -1;
3634
}
3735

3836
private int getH(TreeNode root) {
39-
if (root == null)
40-
return 0;
37+
if (root == null) return 0;
4138
int leftH = getH(root.left);
42-
if (leftH == -1)
43-
return -1;
39+
if (leftH == -1) return -1;
4440
int rightH = getH(root.right);
45-
if (rightH == -1)
46-
return -1;
47-
if (Math.abs(leftH - rightH) > 1)
48-
return -1;
41+
if (rightH == -1) return -1;
42+
if (Math.abs(leftH - rightH) > 1) return -1;
4943
return Math.max(leftH, rightH) + 1;
5044
}
5145
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy