[LeetCode] 111. Minimum Depth of Binary Tree
2017-06-27 19:42
369 查看
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.
The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
// BFS class Solution { public: int minDepth(TreeNode* root) { if (root == nullptr) return 0; int Depth = 1; queue<TreeNode *> q; q.push(root); q.push(nullptr); while (!q.empty()) { TreeNode *ptn = q.front(); q.pop(); if (ptn == nullptr) { Depth++; q.push(nullptr); continue; } if (ptn->left == nullptr && ptn->right == nullptr) break; if (ptn->left) q.push(ptn->left); if (ptn->right) q.push(ptn->right); } return Depth; } };
相关文章推荐
- LeetCode 543. Diameter 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】104. Maximum Depth of Binary Tree
- [leetcode] 104. Maximum 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 105,106. Construct Binary Tree 重建二叉树 Python Solution
- [LeetCode]--104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- LeetCode 104. Maximum Depth of Binary Tree
- leetcode:104. Maximum Depth of Binary Tree
- [leetcode]: 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- [LeetCode] 543. Diameter of Binary Tree
- LeetCode 111. Minimum Depth of Binary Tree
- Leetcode-111. Minimum Depth of Binary Tree