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;
}
}
题目描述
左右取最大。
class Solution {
public int maxDepth(TreeNode root) {
if(root == null){
return 0;
}
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
}
}
本文标题:剑指 Offer 第55-1题:二叉树的深度
本文链接:https://www.haomeiwen.com/subject/wtobbrtx.html
网友评论