[LeetCode] 111. Minimum Depth of Binary Tree
来源:互联网 发布:造粉神器软件 编辑:程序博客网 时间:2024/05/22 11:38
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.
// BFSclass 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; }};
阅读全文
0 0
- 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
- 111. Minimum Depth of Binary Tree LeetCode
- 【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
- 111.[Leetcode]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
- 网页前端学习——基础架构
- 基于PiggyMetrics微服务搭建的分布式系统
- dfs版SPFA判负环
- -----背包 DP hdu 5119- Happy Matt Friends
- 报错 ImportError: No module named 'geohash' 的解决办法
- [LeetCode] 111. Minimum Depth of Binary Tree
- android 通过Scheme链接启动app
- 1000.函数求值
- 日常总结
- Aop切入点的表达式
- Linux NFS
- 台湾大学林轩田机器学习技法课程学习笔记2 -- Dual Support Vector Machine
- Python Dict的用法
- Android---策略模式