111-e-Minimum Depth of Binary Tree
来源:互联网 发布:mac 命令行 删除软件 编辑:程序博客网 时间:2024/05/29 01:52
求二叉树的最小深度。这题好像是以前漏写的。
很明显要广搜了,但自己懒得写队列了,于是就用深搜写的,每次记录最小的level就行。注意判断叶子和层次的对应关系就行。另外预置的层次1024在oj时还太小会出错(该用例测试层次是1800多的单二叉树),所以改为10240.
如下:
void dfsBT(struct TreeNode *node, int level, int *result) { if (node == NULL) return; if (node->left == NULL && node->right == NULL) { if (level < *result) *result = level; return; } dfsBT(node->left, level + 1, result); dfsBT(node->right, level + 1, result);}int minDepth(struct TreeNode* root) { if (root == NULL) return 0; int result = 10240; dfsBT(root, 1, &result); return result;}
0 0
- 111-e-Minimum Depth of Binary Tree
- 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
- 111Minimum Depth of Binary Tree
- 111Minimum 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
- 游戏人物
- 69. Sqrt(x)
- POJ 2236-Wireless Network(并查集)
- nginx负载均衡配置
- iOS UIDevice- NSBundle - NSlocale
- 111-e-Minimum Depth of Binary Tree
- bzoj 3876(有上下界的最小费用流)
- 游戏人物 退出江湖
- 【再谈后缀自动机(入门)】[SPOJLCS2]Longest Common Substring II
- h264 NAL头解析
- 进程调度
- 喷水装置(一)t贪心算法
- 20160406servlet学习笔记验证码
- LeetCode 12 Integer to Roman