递归,非常简单
public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
public int maxDepth (TreeNode root) {
// write code here
return deepth(root);
}
public int deepth(TreeNode root){
if (root == null){
return 0;
}
return Math.max(deepth(root.right),deepth(root.left)) + 1;
}
}
京公网安备 11010502036488号