题解 | #二叉树的最大深度#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
树的高度等于左右子树的最大高度。没啥好说的。
import java.util.*;
public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
public int maxDepth (TreeNode root) {
// write code here
return maxDepth(root,0);
}
public int maxDepth (TreeNode root,int n) {
if(null==root)
return n;
return Math.max(maxDepth(root.left,n+1),maxDepth(root.right,n+1));
}
}