int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
return max(maxDepth(root->left),maxDepth(root->right))+1;
}
二叉树的最大深度
原创
©著作权归作者所有:来自51CTO博客作者别理我我很的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【数据结构】二叉树的存储结构
【数据结构】第五章——树与二叉树详细介绍二叉树的存储结构……
二叉树 数据结构 C语言 -
二叉树的最大深度【二叉树】【递归】
时间复杂度:空间复杂度:
python 复杂度 Code 空间复杂度 -
【二叉树】二叉树最大宽度
题目给定一个二叉树编写一个函数来获取这个树的 最大宽度树的宽度是 所空
swift 算法 二叉树 满二叉树 五笔 -
129,二叉树的最大深度
给定一个二叉树,找出其最大深度。二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。说明: 叶子节点是指
二叉树 子节点 最大深度 最长路 非递归 -
367,二叉树的最大深度
想了解更多数据结构以及算法题,可以关注微信公众号“数据结构和算法”,每天一题为你精彩解答。也可以扫描下面的二维码关注问
二叉树 深度 详解 LeetCode 算法