LeetCode104: Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.
The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
int maxDepth(struct TreeNode* root) {
if (root == NULL)
{
return ;
}
int left = maxDepth(root->left);
int right = maxDepth(root->right);
if (left > right) {
left = left+;
return left;
}else
{
right = right;
return right;
}
}
LeetCode104: Maximum Depth of Binary Tree的更多相关文章
- LeetCode 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
104. 二叉树的最大深度 104. Maximum Depth of Binary Tree 题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说 ...
- [LintCode] Maximum Depth of Binary Tree 二叉树的最大深度
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- [Leetcode][JAVA] Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
LeetCode:Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 33. Minimum Depth of Binary Tree && Balanced Binary Tree && Maximum Depth of Binary Tree
Minimum Depth of Binary Tree OJ: https://oj.leetcode.com/problems/minimum-depth-of-binary-tree/ Give ...
- Leetcode | Minimum/Maximum Depth of Binary Tree
Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum depth is the n ...
- 104. Maximum Depth of Binary Tree(C++)
104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
随机推荐
- MySQL "replace into" 的坑
MySQL 对 SQL 有很多扩展,有些用起来很方便,但有一些被误用之后会有性能问题,还会有一些意料之外的副作用,比如 REPLACE INTO. 比如有这样一张表: CREATE TABLE `au ...
- 深入理解OpenERP的工作流(Workflow)
一.工作流定义: <?xml version="1.0"?> <terp><data> <record model="w ...
- QCon 2015 阅读笔记 - 团队建设
QCon 2015阅读笔记 QCon 2015 阅读笔记 - 移动开发最佳实践 QCon 2015 阅读笔记 - 团队建设 中西对话:团队管理的五项理论和实战 - 谢欣.董飞(今日头条,LinkedI ...
- 【原创】牛顿法和拟牛顿法 -- BFGS, L-BFGS, OWL-QN
数据.特征和数值优化算法是机器学习的核心,而牛顿法及其改良(拟牛顿法)是机器最常用的一类数字优化算法,今天就从牛顿法开始,介绍几个拟牛顿法算法.本博文只介绍算法的思想,具体的数学推导过程不做介绍. 1 ...
- 嵌入式 C 语言的可变参数表函数的设计
首先在介绍可变参数表函数的设计之前,我们先来介绍一下最经典的可变参数表printf函数的实现原理.一.printf函数的实现原理在C/C++中,对函数参数的扫描是从后向前的.C/C++的函数参数是通过 ...
- PreferenceActivity使用方法
public class MainActivity extends Activity { @Override protected void onCreate(Bundle save ...
- Loadrunner 性能指标定位系统瓶颈
判断CPU瓶颈 1, %processor time 平均值大于95 2, processor queue length大于2 (大于处理器个数+1).可以确定CPU瓶颈 3, CPU空闲时间为零(z ...
- 【转】Linux下创建、销毁、使用 SWAP
转自:http://blog.csdn.net/wxqee/article/details/7970110 创建swap文件方法 1) 创建一个足够大的文件 dd if=/dev/zero of=/l ...
- Selenium2Library系列 keywords 之 _SelectElementKeywords 之 select_from_list_by_label(self, locator, *labels)
def select_from_list_by_label(self, locator, *labels): """Selects `*labels` from list ...
- Cocos2d-android (03) 向量
向量的基本运算及动作 import org.cocos2d.actions.interval.CCJumpBy; import org.cocos2d.actions.interval.CCMoveB ...