leetCode 之 Maximum Depth of Binary Tree
2015-06-09 11:01
405 查看
LeetCode : Maximum Depth of Binary Tree
题目原意:求二叉树的最大深度
注意:采用递归,要特别注意返回条件
代码如下(leetCode 测得运行时间为4ms):
题目原意:求二叉树的最大深度
注意:采用递归,要特别注意返回条件
代码如下(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 ; } }
相关文章推荐
- 使用@Transactional时候的注意点
- Memory Debuggers
- Android 自定义View使用示例(三)
- [LeetCode] Contains Duplicate
- 数值的整数次方
- XCode编译速度慢的处理方法
- lib工程被引用的时候出现Unable to execute dex: Multiple dex files define。和classNoClassDefFoundError错误
- RubyGem默认源安装太慢,修改国内淘宝源
- C++模板
- 原码, 反码, 补码 详解
- 条形码barcode4j的使用
- java处理barCode条形码
- 【转】MySQL GRANT REVOKE用法
- Android PopupWindow使用实例
- 解决iframe内弹窗鼠标滚轮事件失效
- NOSQL----memcached(临时键值存储数据库)在centos下的安装与启动
- CocoaPods安装和使用教程 自我实践
- 数据结构基础
- STM32的BootLoader 从SD卡更新固件
- string转datetime