lintcode二叉树的最小深度
来源:互联网 发布:windows文件夹加密码 编辑:程序博客网 时间:2024/06/03 19:21
二叉树的最小深度
给定一个二叉树,找出其最小深度。
二叉树的最小深度为根节点到最近叶子节点的距离。
样例
给出一棵如下的二叉树:
1
/ \
2 3
/ \
4 5
这个二叉树的最小深度为 2
标签
相关题目
class Solution {public: int minDepth(TreeNode *root) { if (root == NULL) return 0; if (root->left == NULL && root->right == NULL) return 1; if (root->left == NULL) return minDepth(root->right) + 1; else if (root->right == NULL) return minDepth(root->left) + 1; else return 1 + min(minDepth(root->left), minDepth(root->right)); } };
阅读全文
0 0
- LintCode 二叉树的最小深度
- lintcode-二叉树的最小深度-155
- LintCode:二叉树的最小深度
- lintcode ----二叉树的最小深度
- Lintcode 二叉树的最小深度
- LintCode-二叉树的最小深度
- lintcode 二叉树的最小深度
- LintCode 二叉树的最小深度
- 二叉树的最小深度-LintCode
- lintcode 二叉树的最小深度
- LintCode 二叉树的最小深度
- lintcode 155 二叉树的最小深度
- LintCode 155-二叉树的最小深度
- 二叉树的最小深度-LintCode
- lintcode二叉树的最小深度
- lintcode——二叉树的最小深度
- lintcode(E) 二叉树最小深度
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- 正则表达式各种符号含义
- Nginx PHP 文件上传 500错误
- ssh 实现多台主机免密登陆并附带多种错误解决办法
- Caffe中实现LSTM网络的思路以及LSTM网络层的接口使用方法。 本文描述了论文《Long-term recurrent convolutional networks fo
- php 正则表达式
- lintcode二叉树的最小深度
- table 元素使用案例(设置工单表格)
- HTML5实践——拖放
- 内联成员函数
- Server Tomcat v7.0 Server at localhost failed to start.
- 170907 WarGames-Behemoth(5-6)
- 周中训练笔记3
- 关于 oracle NULL
- 神经网络中end-to-end training和end-to-end models的区别