leetcode 111 Minimum Depth of Binary Tree
来源:互联网 发布:蜂窝数据漫游是什么 编辑:程序博客网 时间:2024/06/06 07:18
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.
Subscribe to see which companies asked this question
class Solution {public:int minDepth(TreeNode *root) {if(root==NULL) return 0;queue<TreeNode*> q;q.push(root);q.push(NULL);int height=1;while(!q.empty()) {TreeNode *temp = q.front();q.pop();if(temp!=NULL) {if(temp->left==NULL && temp->right==NULL) break;if(temp->left!=NULL)q.push(temp->left);if(temp->right!=NULL)q.push(temp->right);} else {height++;q.push(NULL);}}return height;}}
0 0
- LeetCode(111)Minimum Depth of Binary Tree
- LeetCode: Minimum Depth of Binary Tree [111]
- LeetCode 111 Minimum Depth of Binary Tree
- [leetcode 111] Minimum Depth of Binary Tree
- [LeetCode 111]Minimum Depth of Binary Tree
- leetCode #111 Minimum Depth of Binary Tree
- leetcode-111 Minimum Depth of Binary Tree
- leetcode 111 Minimum Depth of Binary Tree
- leetcode || 111、Minimum Depth of Binary Tree
- Leetcode[111]-Minimum Depth of Binary Tree
- leetcode[111]:Minimum Depth of Binary Tree
- LeetCode 111 Minimum Depth of Binary Tree
- [leetcode 111] Minimum Depth of Binary Tree
- leetcode-111-Minimum Depth of Binary Tree
- Leetcode #111 Minimum Depth of Binary Tree
- leetcode 111: Minimum Depth of Binary Tree
- LeetCode 111: Minimum Depth of Binary Tree
- 【LEETCODE】111-Minimum Depth of Binary Tree
- Java\Scala\Python三种语言求解经典编程实例(四)—— 求10000以内的自守数
- Contains Duplicate II
- 装箱和拆箱
- Leetcode_c++:Construct Binary Tree from Preorder and Inorder Traversal(105)
- 欢迎使用CSDN-markdown编辑器
- leetcode 111 Minimum Depth of Binary Tree
- KMP算法详解
- CentOS 6.4+nginx+php+mysql详细设置步骤
- 顶层const 与底层const
- R语言-时间函数
- java-计数器
- python学习笔记注意要点
- 简单实现Redis缓存中的排序功能
- [Android] ScrollView 垂直滚动控件和 HorizontalScrollView 水平滚动控件的使用