LeetCode111——Given a binary tree, find its minimum depth.
来源:互联网 发布:机械公差配合软件 编辑:程序博客网 时间:2024/05/21 13:21
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
之后发的文章就不翻译了,因为一般读这个文章的人都是刷LeetCode的人,读题目应该不成问题,我就不做多余的翻译了。
难度系数:
容易
实现
int minDepth(TreeNode *root) { if (root == NULL) return 0; queue<TreeNode*> q; q.push(root); int mindepth = 1; TreeNode* node; while (!q.empty()) { vector<TreeNode*> vt; while (!q.empty()) { node = q.front(); q.pop(); vt.push_back(node); } for (int i = 0; i < vt.size(); ++i) { node = vt[i]; if (node->left == NULL && node->right == NULL) { return mindepth; } if (node->left) { q.push(node->left); } if (node->right) { q.push(node->right); } } mindepth += 1; } return mindepth;}
0 0
- LeetCode111——Given a binary tree, find its minimum depth.
- LeetCode111—Minimum Depth of Binary Tree
- Given a binary tree, find its maximum depth.
- leetcode111---Minimum Depth of Binary Tree
- LeetCode111:Minimum Depth of Binary Tree
- [leetcode111].Minimum Depth of Binary Tree
- leetcode111~Minimum Depth of Binary Tree
- LeetCode111 Minimum Depth of Binary Tree
- leetcode111. Minimum Depth of Binary Tree
- LeetCode111. Minimum Depth of Binary Tree
- LeetCode111. Minimum Depth of Binary Tree
- Minimum Depth of a Binary Tree
- LeetCode——Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree——LeetCode(Easy)
- LeetCode——Minimum Depth of Binary Tree
- leetcode 111 —— Minimum Depth of Binary Tree
- 算法系列——Minimum Depth of Binary Tree
- LeetCode——111. Minimum Depth of Binary Tree
- 设置UISearchBar的按钮字体样式
- BZOJ大视野 1059: [ZJOI2007]矩阵游戏 解题报告
- zoj 1331 Perfect Cubes
- rman的维护监控和报告crosscheck,list,report,change
- 西安石油化工技工学校浅谈石油化工行业
- LeetCode111——Given a binary tree, find its minimum depth.
- web安全防范之XSS漏洞攻击
- 一步步了解View(二)——View的绘制
- rman高级恢复主题
- 求一个字符串中连续出现次数最多的子串
- Spinner下拉列表
- Android_JSON解<一>
- 1.2.2 5 TFTP服务配置
- ubuntu下单机hadoop环境部署