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 c6a817c commit 5fe9b18Copy full SHA for 5fe9b18
maximum-depth-of-binary-tree/jinhyungrhee.java
@@ -0,0 +1,17 @@
1
+class Solution {
2
+ public int maxVal;
3
+ public int maxDepth(TreeNode root) {
4
+ dfs(root, 0);
5
+ return maxVal;
6
+ }
7
+ public void dfs(TreeNode node, int step) {
8
+
9
+ if (node == null) {
10
+ if (maxVal < step) maxVal = step;
11
+ return;
12
13
14
+ dfs(node.left, step + 1);
15
+ dfs(node.right, step + 1);
16
17
+}
0 commit comments