Skip to content

Commit 9485c04

Browse files
authored
Add files via upload
1 parent 0919e8a commit 9485c04

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

DepthOfBinaryTree.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class DepthOfBinaryTree {
2+
3+
public int maxDepth(TreeNode root) {
4+
return dfs(root,0);
5+
}
6+
7+
public int dfs(TreeNode root, int depth) {
8+
if(root!=null) {
9+
depth++;
10+
return Math.max(dfs(root.left,depth),dfs(root.right,depth));
11+
}
12+
return depth;
13+
}
14+
15+
}

0 commit comments

Comments
 (0)