leetcode_question_111 Minimum Depth of Binary Tree
来源:互联网 发布:知彼定位软件 编辑:程序博客网 时间:2024/05/18 02:13
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.
int minDepth(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root == NULL) return 0; queue<TreeNode*> que; que.push(root); int count = 1; int depth = 0; while(!que.empty()) { TreeNode* tmp = que.front(); que.pop(); count--; if(tmp->left == NULL && tmp->right == NULL) break; if(tmp->left) que.push(tmp->left); if(tmp->right) que.push(tmp->right); if(count == 0){ depth++; count = que.size(); } } return ++depth; }
- leetcode_question_111 Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- 向循环有序链表内插入一个节点
- MySQL 错误记录
- 非阻塞模式WinSock编程入门
- Guava缓存器源码分析——删除消息
- C#获取客户端计算机硬件及系统信息
- leetcode_question_111 Minimum Depth of Binary Tree
- 通过网页实现软件的布局
- HDU4720----Naive and Silly Muggles
- memcached的分布式算法
- Java数组常用的十个方法
- Python 网页抓取及相关: (1)获取源码及检索
- 青春,请不要毕业
- 关于c#中的Timer控件的简单用法
- C++中认识的第一个函数获取数组的大小