/**
* 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) {
if (root==null) return 0;
int res = 0;
return res = Math.max(maxDepth(root.left)+1, maxDepth(root.right)+1);
}
}
DP + recursive
回复删除