<pre name="code" class="java">/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int maxDepth(TreeNode root) {
return root==null ? 0 : Math.max(1+maxDepth(root.left), 1+maxDepth(root.right));
}
}