package org.example.leetcodeBook.deepSearch;
//二叉树的最大深度
//给定一个二叉树 root ,返回其最大深度。
//二叉树的 最大深度 是指从根节点到最远叶子节点的最长路径上的节点数。
public class MaxDepthSolution {
public int maxDepth(InorderTraversalSolution.TreeNode root){
if(root==null)return 0;
else{
int leftHeight = maxDepth(root.left);
int rightHeight = maxDepth(root.right);
return Math.max(leftHeight,rightHeight)+1;
}
}
}
二叉树的最大深度
最新推荐文章于 2025-12-26 18:13:00 发布

1075

被折叠的 条评论
为什么被折叠?



