Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
来源:互联网 发布:大三c语言编程题库 编辑:程序博客网 时间:2024/05/08 05:37
题目:
链接
解答:
深搜,剪枝搜索过程中深度大于最小值的情况。
代码:
class Solution {public:int minDepth(TreeNode *root) {if (root == NULL)return 0;int min = INT_MAX;search(root, 1, min);return min;}void search(TreeNode *root, int deep, int &min){if (deep > min)return;if (root->left == NULL && root->right == NULL){if (deep < min)min = deep;}else{if (root->left != NULL)search(root->left, deep + 1, min);if (root->right != NULL)search(root->right, deep + 1, min);}}};
0 0
- Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- Minimum Depth of Binary Tree 二叉树最小深度
- Leetcode Minimum Depth of Binary Tree 二叉树最小深度
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- LeetCode:minimum-depth-of-binary-tree(二叉树最小深度)
- 求二叉树的最小深度 Minimum Depth of Binary Tree
- LeetCode OJ 之 Minimum Depth of Binary Tree(二叉树的最小深度)
- [Java代码] [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- 155.Minimum Depth of Binary Tree-二叉树的最小深度(容易题)
- Minimum Depth of Binary Tree(求二叉树的最小深度)
- leetcode_111. Minimum Depth of Binary Tree 二叉树的最小深度
- [LeetCode]111. Minimum Depth of Binary Tree--二叉树的最小深度
- Hdu 4941 Magical Forest(map+离散化)
- HDU 1039 Easer Done Than Said?
- uilib库gdi句柄泄漏bug修复,duilib防止gdi泄漏的小提醒
- 技术经验总结
- Android增加一个物理按键检测步骤
- Minimum Depth of Binary Tree -- 二叉树的最小深度 DFS 加剪枝
- 函数将返回
- HDU 1754 线段树+深搜 数据结构
- 设计模式 之 外观
- poj 3321(很好的题目,参看了很多资料才整出来的)
- 微信公众平台SDK for node
- leetcode Longest Consecutive Sequence
- antest分配值
- JSP 简明教程(二):JSP基本语法