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)