LeetCode: Maximum Depth of Binary Tree

LeetCode: Maximum Depth of Binary Tree

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

/**
* Created by hzhou on 4/27/15. [email protected]
*/
public class MaximumDepthOfBinaryTree {
public int maxDepth(TreeNode root) {
return helper(root);
}
private int helper(TreeNode root) {
if (root == null) {
return 0;
} else {
return Math.max(helper(root.left), helper(root.right)) + 1;
}
}
}