简单题。顺手就写出来了。

public class Solution {
    public int maxDepth(TreeNode root) {
        // Start typing your Java solution below
        // DO NOT write main() function        
        if (root == null) return 0;
        if (root.left == null && root.right == null) return 1;
        int lmax = maxDepth(root.left) + 1;
        int rmax = maxDepth(root.right) + 1;
        return Math.max(lmax, rmax);       
    }
}

  

相关文章:

  • 2022-02-15
  • 2021-09-23
  • 2021-08-14
  • 2021-05-02
  • 2021-12-10
  • 2021-09-07
猜你喜欢
  • 2021-12-13
  • 2021-09-24
  • 2021-07-28
  • 2021-09-01
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案