leetcode Maximum Depth of Binary Tree
来源:互联网 发布:简单好学的软件 编辑:程序博客网 时间:2024/06/05 16:33
找到二叉树中的最大深度
递归方法
对于某一结点来说,分别找到其左右子树的最大深度,则此节点的最大深度为左右子树的较大者+1,加1为包含该节点所在的这一层。
代码
class Solution {public: int maxDepth(TreeNode *root) { if(root==NULL) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); return max(left, right)+1; }};
0 0
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- Leetcode: Maximum Depth of Binary Tree
- LeetCode-Maximum Depth of Binary Tree
- [leetcode] Maximum Depth of Binary Tree
- LeetCode - Maximum Depth of Binary Tree
- LeetCode:Maximum Depth of Binary Tree
- LeetCode | Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- Linux 添加用户 ,帐号管理 ,群组管理 详解
- zoj 1010
- Java基础<异常机制>总结(异常体系、Exception特点、异常处理方式)
- ANTLR4权威指南 - 第5章 设计语法
- 淘宝数据库OceanBase SQL编译器部分 源码阅读--解析SQL语法树
- leetcode Maximum Depth of Binary Tree
- 人生就是无限的将一只脚放到另外一只脚前面的过程
- hdu 4968 Improving the GPA(暴力枚举)
- hdu 4970 Killing Monsters 多校九 求和
- Java中DatabaseMetaData 元数据信息 .
- java学习笔记4
- 详解LMA(装载内存地址)与VMA(虚拟内存地址)
- OceanBase 快速入门_3 源码结构
- 协议系列之TCP协议