leetCode 之 Maximum Depth of Binary Tree
来源:互联网 发布:mac自动播放照片 编辑:程序博客网 时间:2024/05/17 07:05
LeetCode : Maximum Depth of Binary Tree
题目原意:求二叉树的最大深度
注意:采用递归,要特别注意返回条件
题目原意:求二叉树的最大深度
注意:采用递归,要特别注意返回条件
代码如下(leetCode 测得运行时间为4ms):
int maxDepth(struct TreeNode *root){int depth_right = 1;int depth_left = 1;if (!root){return 0;}while(root) //!< 采用递归,注意返回条件{if (root->left){depth_left = depth_left + maxDepth(root->left);}if (root->right){depth_right = depth_right + maxDepth(root->right);}return depth_left >= depth_right ? depth_left : depth_right ;}}
0 0
- 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
- 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(Java版)
- LeetCode之路:104. Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- RubyGem默认源安装太慢,修改国内淘宝源
- 使用@Transactional时候的注意点
- lib工程被引用的时候出现Unable to execute dex: Multiple dex files define。和classNoClassDefFoundError错误
- 原码, 反码, 补码 详解
- 条形码barcode4j的使用
- leetCode 之 Maximum Depth of Binary Tree
- asp.net 导入excel表格
- 项目调试Assertion failed
- 上海英语播音学校比较好
- 使用DialogFragment托管dialog
- GRE词汇分类之与装修词汇
- Memory Debuggers
- Android Studio 类库中配置Jpush 报错 java.lang.UnsatisfiedLinkError解决方案
- Ubuntu 14.04一步一步安装Openstack Kilo版本-2