题解 | #二叉树的最大深度#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
实现原理:递归,比较出最大深度
public class Solution {
/**
*
* @param root TreeNode类
* @return int整型
*/
public int maxDepth (TreeNode root) {
// write code here
if (root==null)
return 0;
//递归
int dl = maxDepth(root.left)+1;
int dr = maxDepth(root.right)+1;
//比较深度大小
if (dl>dr)
return dl;
else
return dr;
}
}