Minimum Depth of Binary Tree
来源:互联网 发布:2015网络彩票开售 编辑:程序博客网 时间:2024/06/05 06:51
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.
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int minDepth(TreeNode *root) { if(root == 0) return 0; int a = minDepth(root->left); int b = minDepth(root->right); if(a*b != 0) return min(a,b) + 1; else if(a == 0) return b + 1; else return a + 1; }};
0 0
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- 一个比较全面的java随机数据生成工具包
- HDOJ1084 What Is Your Grade?
- oracle操作命令大全
- 数据结构与算法:哈夫曼树(源码)!
- 自定义显示圆形图片
- Minimum Depth of Binary Tree
- 编辑文章 - 博客频道 - CSDN.NET
- Master-Mind Hints
- Android NDK入门
- CoNLL Multi-lingual Dependency Parsing 格式
- mysql 源码编译安装
- 不错网站推荐不定期更新
- 180行ruby代码搞定游戏2048
- 嵌入Chrome cef之完整版(本教程基于cef1)