/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int maxDepth(TreeNode root) {
return getMaxDepth(root, 0);
}
private int getMaxDepth(TreeNode root, int depth) {
if (root == null)
return depth;
depth++;
int leftDepth = getMaxDepth(root.left, depth);
int rightDepth = getMaxDepth(root.right, depth);
int max = Math.max(leftDepth, rightDepth);
return max;
}
}