Skip to content

Commit 7ffd59c

Browse files
authored
104. Maximum Depth of Binary Tree Solution added (#9)
* 104. Maximum Depth of Binary Tree Solution added * resolved * resubbmitted
1 parent 596afd8 commit 7ffd59c

File tree

1 file changed

+21
-0
lines changed
  • Algorithms/Easy/104_MaximumDepthOfBinaryTree

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Definition for a binary tree node.
3+
* public class TreeNode {
4+
* public int val;
5+
* public TreeNode left;
6+
* public TreeNode right;
7+
* public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) {
8+
* this.val = val;
9+
* this.left = left;
10+
* this.right = right;
11+
* }
12+
* }
13+
*/
14+
public class Solution {
15+
public int MaxDepth(TreeNode root) {
16+
if (root == null) return 0;
17+
int leftTree = MaxDepth(root.left) + 1;
18+
int rightTree = MaxDepth(root.right) + 1;
19+
return leftTree >= rightTree ? leftTree : rightTree;
20+
}
21+
}

0 commit comments

Comments
 (0)