1. class Solution {
    2. public int maxDepth(TreeNode root) {
    3. //1:递归条件
    4. if(root == null){
    5. return 0;
    6. }
    7. //2: 递归方法
    8. //这个写法非常精妙 递归的含义是:取左子树和右子树中,最深的一层,在加上本层自己的深度(+1)
    9. return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
    10. }
    11. }