题目描述:
    image.png
    image.png
    解析:方法1:同39题,即求res的长度 方法2:递归
    本次代码用递归求解

    1. class Solution {
    2. public int maxDepth(TreeNode root) {
    3. if (root == null) return 0;
    4. int leftDepth = maxDepth(root.left);
    5. int rightDepth = maxDepth(root.right);
    6. return Math.max(leftDepth, rightDepth) + 1;
    7. }
    8. }