Leetcode 111
来源:互联网 发布:程序员用什么键盘好 编辑:程序博客网 时间:2024/06/04 19:37
Leetcode 111, Minimum Depth of Binarytree, 难度easy
这道题跟112是一样的,只要稍微的改一下就可以了,也就是在每一次递归时将层数加一,最后对比左子树和右子树的层数,将小的层数返回。
class Solution {public: int minDepth(TreeNode* root) { int res = 0; if(root == NULL) return 0; return DFS(root, res); } int DFS(TreeNode* root, int res) { res++; int left = root -> left == NULL? (root -> right == NULL? res: INT_MAX) : DFS(root -> left, res); int right = root -> right == NULL? (root -> left == NULL? res: INT_MAX) : DFS(root -> right, res); if(left < right) return left; return right; }};
阅读全文
0 0
- Leetcode 111
- leetcode 111: Distinct Subsequences
- leetcode #111 in cpp
- Leetcode no. 111
- leetCode练习(111)
- LeetCode@111_Minimum_Depth_of_Binary_Tree
- [Leetcode] 95, 109, 111
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- Android——蓝牙Socket通信
- Logstash事件字段遍历
- Python SSH 的远程连接并执行命令和下载文件
- hdu 1232 畅通工程(并查集)
- codeforces Codeforces Round #407 Div2题解 B,C,D,E
- Leetcode 111
- 无限制获取GPS对应地址的一种方法
- 如何禁止浏览器中点回退按钮能回退到上一页?
- 精确显示本机ip 带颜色醒目效果
- 模板:并查集
- Dev 获取checkedListBoxControl值
- 170923_Spring英文文档阅读(十四)_2.3 Usage scenarios_Dependency Management and Naming Conventions(一)
- 第三方开发者模式
- ThinkPHP 图片上传 改路径上传