class solution {
/**
* 递归法
*/
public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}
int leftDepth = maxDepth(root.left);
int rightDepth = maxDepth(root.right);
return Math.max(leftDepth, rightDepth) + 1;
}
}
104.二叉树最大的深度
最新推荐文章于 2024-07-15 22:27:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)