Minimum Depth of Binary Tree
来源:互联网 发布:僵直脊柱炎周杰伦知乎 编辑:程序博客网 时间:2024/06/06 17:05
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) { return subMinDepth(root,0); } int subMinDepth(TreeNode *node,int curDepth){ if(node==NULL){ return curDepth; } curDepth++; int left=subMinDepth(node->left,curDepth); int right=subMinDepth(node->right,curDepth); if(node->left==NULL) return right; else if(node->right==NULL) return left; if(left>right) return right; else return left; }};
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
- Android开发系列(二十四):Notification的功能与用法
- java 将jso 格式的字符串转换为List<Map<String,String>>
- UVa 11121 - Base -2
- hdu 1075 What Are You Talking About(字典树)
- 20款让人惊叹的html5动画效果
- Minimum Depth of Binary Tree
- C语言编程代码分析0
- C/C++中static关键字详解
- The Triangle
- zoj 3229 (有上下届的最大流)
- 保龄球-----计分程序
- C++中的空类,默认产生哪些类成员函数?
- 如何编写串口(uart)驱动-基于linux310
- 二、Ubuntu14.04下安装Hadoop2.4.0 (伪分布模式)