LeetCode Minimum Depth of Binary Tree
2014-03-11 19:08
330 查看
没什么难度的,刚开始又马虎了。。。
int minDepth(TreeNode *root) { if(root==NULL) return 0; if (root->left==NULL&&root->right!=NULL) { return minDepth(root->right)+1; } else { if (root->left!=NULL&&root->right==NULL) { return minDepth(root->left)+1; } else { if (root->left!=NULL&&root->right!=NULL) { //return minDepth(root->right)+1; int leftMinDepth = minDepth(root->left); int rightMinDepth = minDepth(root->right); return leftMinDepth<rightMinDepth?leftMinDepth+1:rightMinDepth+1; } else { return 1; } } } }
相关文章推荐
- JS常用的正则表达式总结
- Apache mod_wsgi部署Django项目
- BINARY SEARCH in read table statement
- Linux下chkconfig用法详解
- Nginx server之Nginx作为web服务器(基于域名或IP的web服务器)
- MVC中JQuery文件引入的路径问题,@Url.Content函数
- [问题2014S01] 解答
- html5的Input Attr : Autofocus,感觉挺有意思的!
- 关键词提取1-C#
- RSA算法原理
- 排序之选择排序
- intent 分析,显式隐式
- nagios监控服务器
- 开发中用到的一个快速排序法
- FreeBSD---GIT
- jQuery源码学习之总体架构
- glibc-printf
- Visual C++ ADO数据库编程入门(下)
- Visual Studio Intellisense、Eclipse Content Assist与理念式编程
- SAP 金额在表中的存储及货币转换因子