Skip to content

Commit f0d1f71

Browse files
committed
Updated maxDepth
1 parent c28fb30 commit f0d1f71

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Easy/MaxDepth.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@ public static void main(String[] args) {
1919
* Get the max depth of right subtree recursively
2020
* Get the max of max depths of left and right subtrees and add 1 to it
2121
*/
22-
private static int maxDepth(TreeNode root) {
22+
private int maxDepth(TreeNode root) {
2323
if (root == null) return 0;
2424
int left = maxDepth(root.left);
2525
int right = maxDepth(root.right);
2626
return Math.max(left, right) + 1;
2727
}
28+
29+
class TreeNode {
30+
int val;
31+
TreeNode left;
32+
TreeNode right;
33+
}
2834
}

0 commit comments

Comments
 (0)