Skip to content

Commit 3f164ff

Browse files
refactor 104
1 parent 04108bf commit 3f164ff

File tree

1 file changed

+14
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ public int maxDepth(TreeNode root) {
2121
}
2222

2323
public static class Solution2 {
24+
/**
25+
* A more verbose recursive solution for easier understanding.
26+
*/
27+
public int maxDepth(TreeNode root) {
28+
if (root == null) {
29+
return 0;
30+
}
31+
int left = maxDepth(root.left);
32+
int right = maxDepth(root.right);
33+
return 1 + Math.max(left, right);
34+
}
35+
}
36+
37+
public static class Solution3 {
2438
/**
2539
* Iterative solution:
2640
* Time: O(n)

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