二叉树遍历111. Minimum Depth of Binary Tree
来源:互联网 发布:科目二约车软件 编辑:程序博客网 时间:2024/05/17 07:48
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int minDepth(TreeNode* root) { // 因为树可能很不均衡,所以采用BFS,即找到最短的路径就结束;当然dfs也可以,或者效仿上面的maxDepth也行(dfs) // 算了我屈服还是用dfs吧 if(root == NULL) return 0; if (root->left == NULL && root->right == NULL) return 1; if (root->left == NULL) return minDepth(root->right)+1; if (root->right == NULL) return minDepth(root->left) +1; return min(minDepth(root->left), minDepth(root->right))+1 ;//也就是最后一种情况 }};
有用队列写的给我发一下代码啊233
0 0
- 二叉树遍历111. Minimum Depth of Binary Tree
- 【二叉树】111. Minimum Depth of Binary Tree
- 【二叉树】计算二叉树深度【104. Maximum Depth of Binary Tree】【111. Minimum Depth of Binary Tree】
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- 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 二叉树的最小深度
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- LeetCode:minimum-depth-of-binary-tree(二叉树最小深度)
- leetcode 111.Minimum Depth of Binary Tree-树最小深度|深度遍历|广度遍历
- 二叉树遍历104. Maximum Depth of Binary Tree
- leetCode 111.Minimum Depth of Binary Tree(二叉树最小深度) 解题思路和方法
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- LeetCode 111. Minimum Depth of Binary Tree(二叉树最小深度)
- 111. Minimum Depth of Binary Tree 二叉树的最小深度
- Leetcode 111. Minimum Depth of Binary Tree 二叉树最小深度
- 实现js输入框只允许输入金额
- C语言的简单小例题程序
- Hibernate实体关系关联映射中配置文件的编写
- BookList
- CUDA-CODE4-并行编程-blockIDx
- 二叉树遍历111. Minimum Depth of Binary Tree
- input type=number验证问题
- Java文件切片 & 切片合并代码
- python os 模块的应用
- java 取目前操作系统桌面路径
- Razor引擎学习:RenderBody,RenderPage和RenderSection
- 导入excel数据到数据库
- JQuery学习&资料整理
- redis集合set的相关命令