[LeetCode] Minimum Depth of Binary Tree
来源:互联网 发布:智能电视点歌软件 编辑:程序博客网 时间:2024/06/06 19:29
Given a binary tree, find its minimum depth.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
» Solve this problem
[解题报告]
[Code]
1: int minDepth(TreeNode *root) {
2: // Start typing your C/C++ solution below
3: // DO NOT write int main() function
4: if(root == NULL)
5: return 0;
6: int lmin = minDepth(root->left);
7: int rmin = minDepth(root->right);
8: if(lmin ==0 && rmin ==0)
9: return 1;
10: if(lmin ==0)
11: {
12: lmin = INT_MAX;
13: }
14: if(rmin ==0)
15: {
16: rmin = INT_MAX;
17: }
18: return min(lmin, rmin) +1;
19: }
0 0
- LeetCode: Minimum Depth of Binary Tree
- [Leetcode] Minimum Depth of Binary Tree
- LeetCode : Minimum Depth of Binary Tree
- leetcode 31: Minimum Depth of Binary Tree
- [LeetCode] Minimum Depth of Binary Tree - BFS
- [LeetCode] Minimum Depth of Binary Tree - DFS
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree
- [Leetcode]Minimum Depth of Binary Tree
- [leetcode]Minimum Depth of Binary Tree
- Leetcode: Minimum Depth of Binary Tree
- LeetCode-Minimum Depth of Binary Tree
- [leetcode] Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- 【Leetcode】Minimum Depth of Binary Tree
- LeetCode | Minimum Depth of Binary Tree
- LeetCode - Minimum Depth of Binary Tree
- [LeetCode] Median of Two Sorted Arrays 解题报告
- [LeetCode] Merge k Sorted Lists 解题报告
- [LeetCode] Merge Sorted Array 解题思路
- 调用活动,通过intent显式调用
- du&df
- [LeetCode] Minimum Depth of Binary Tree
- [LeetCode] Minimum Path Sum 解题报告
- [LeetCode] Minimum Window Substring 解题报告
- [LeetCode] Multiply Strings 解题报告
- [LeetCode] Next Permutation 解题报告
- [LeetCode] Palindrome Number 解题报告
- [LeetCode] Partition List 解题报告
- [LeetCode] Pascal’s Triangle II 解题报告
- Android 之 Fresco 显示圆形图片 之坑