剑指 Offer 第55-1题:二叉树的深度
2022-08-17 本文已影响0人
放开那个BUG
1、前言
题目描述
2、思路
左右取最大。
3、代码
class Solution {
public int maxDepth(TreeNode root) {
if(root == null){
return 0;
}
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}