二叉树最大深度和最小深度
来源:互联网 发布:视频cms php 编辑:程序博客网 时间:2024/05/19 14:01
二叉树的最大深度
int maxDepth(TreeNode *root) { // write your code (here) if(root == NULL) return 0; int leftDepth = maxDepth(root->left); int rightDepth = maxDepth(root->right); return leftDepth > rightDepth ? (leftDepth + 1) : (rightDepth + 1); }
二叉树的最小深度
int minDepth(TreeNode *root) { // write your code here if(root == NULL) return false; if(root->left == NULL && root->right == NULL) return 1; int leftDepth = minDepth(root->left); if(leftDepth == 0) leftDepth = INT_MAX; int rightDepth = minDepth(root->right); if(rightDepth == 0) rightDepth = INT_MAX; return leftDepth < rightDepth ? (leftDepth + 1) : (rightDepth + 1); }
阅读全文
0 0
- 二叉树最大深度和最小深度
- 二叉树最大深度和最小深度
- 二叉树深度(最大和最小)
- 二叉树的最大深度和最小深度
- 二叉树的最大深度和最小深度实现
- 二叉树最大 最小深度
- 二叉树 最大最小深度
- 二叉树的最大深度 & 二叉树的最小深度
- 二叉树的最大深度 & 二叉树的最小深度
- 二叉树的最大最小深度
- 二叉树最大深度最小深度之微妙区别
- 二叉树的最大深度与最小深度
- 二叉树的最大深度与最小深度
- leedcode二叉树的最小深度与最大深度
- 二叉树的最大深度与最小深度
- 二叉树(创建、遍历、树的最大深度和最小深度)
- 求二叉树的最大深度和最小深度以及之间的差
- 二叉树最小深度
- tableview单元格的复用
- Hive学习指南(三)
- css3中的gradient渐变
- 获取元素需判断的条件
- springMVC-笔记002-web配置文件
- 二叉树最大深度和最小深度
- Pro ASP.NET Core MVC(四)【C#关键特征】
- Java中普通代码块、构造代码块、静态代码块的区别?
- swagger-2.6.0 记录一个下午的无聊举动
- hbase基础理论知识
- 零基础 学Python
- springMVC-笔记003-spring配置文件
- 欢迎使用CSDN-markdown编辑器
- hibernate的load()和get()的区别