LeetCode:Minimum Depth of Binary Tree
2013-05-15 20:13
330 查看
宽搜
class Solution { public: int minDepth(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root == NULL) return 0; int level = 1; vector<TreeNode*>tree; tree.push_back(root); int begin = 0; int end = 1; while(begin<end) { TreeNode* node = tree[begin]; if(node->right==NULL&&node->left==NULL) return level; if(node->right) tree.push_back(node->right); if(node->left) tree.push_back(node->left); if(begin == end-1) { end = tree.size(); level++; } begin++; } } };
相关文章推荐
- leetcode-Minimum Depth of Binary Tree
- leetcode_c++:树: Minimum Depth of Binary Tree(111)
- Minimum Depth of Binary Tree -- LeetCode
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
- Minimum Depth of Binary Tree [LeetCode]
- leetcode 日经贴,Cpp code -Minimum Depth of Binary Tree
- leetcode: Minimum Depth of Binary Tree
- 92_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-Maximum/Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree ---LeetCode
- leetcode: Minimum Depth of Binary Tree
- leetcode Minimum Depth of Binary Tree
- [LeetCode-111] Minimum Depth of Binary Tree (二叉树最小深度)
- Leetcode在线编程minimum-depth-of-binary-tree
- leetcode(111):Minimum Depth of Binary Tree
- [LeetCode]Minimum Depth of Binary Tree