题解 | #二叉树的最大深度#
二叉树的最大深度
http://www.nowcoder.com/practice/8a2b2bf6c19b4f23a9bdb9b233eefa73
递归比较左右子树即可。
import java.util.*;
public class Solution {
public int maxDepth (TreeNode root) {
if(root==null)return 0;
if(root.left==null&&root.right==null)return 1;
int leftDepth = maxDepth(root.left)+1;
int rightDepth = maxDepth(root.right)+1;
return leftDepth>rightDepth?leftDepth:rightDepth;
}
}

顺丰集团工作强度 369人发布