Minimum Depth of Binary Tree
来源:互联网 发布:点击淘宝延长收货3天 编辑:程序博客网 时间:2024/06/01 10:49
/** * 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==NULL) { return 0; } if((root->left==NULL)&&(root->right==NULL)) { return 1; } if(root->left==NULL) { int rdepth=minDepth(root->right); return rdepth+1; } else if(root->right==NULL) { int ldepth=minDepth(root->left); return ldepth+1; } else { int ldepth=minDepth(root->left); int rdepth=minDepth(root->right); return ldepth>rdepth?rdepth+1:ldepth+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
- JDK学习笔记18——String1_String的简介以及常见方法
- MongoDB笔记2:MongoDB 目录配置
- JFreeChar自学教程
- Java Web新手小项目及源码
- bzoj3506 [Cqoi2014]排序机械臂
- Minimum Depth of Binary Tree
- Mxmlc Error: could not find a JVM.
- win8.1 安装 PL2303 HXA 驱动教程
- _CRT_SECURE_NO_WARNINGS
- Machine Learning - II. Linear Regression with One Variable单变量线性回归 (Week 1)
- [Android开发笔记]网络图片查看器的完成
- Django1.7.2+Bootstrap3.3.0 整合五:模板与视图
- Boosting算法简介
- 构建高性能网站的14条法则:减少HTTP请求