leetcode104 Maximum Depth
题意:二叉树最大深度
思路:递归,但是不知道怎么回事直接在return里面计算总是报超时,用俩变量就可以A···奇怪,没想通
代码:
int maxDepth(TreeNode* root) {
if(!root)
return ;
int l = maxDepth(root->left)+;
int r = maxDepth(root->right)+;
return (l > r) ? l : r;
}
leetcode104 Maximum Depth的更多相关文章
- LeetCode104: 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 104. 二叉树的最大深度(Maximum Depth of Binary Tree)
104. 二叉树的最大深度 104. Maximum Depth of Binary Tree 题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说 ...
- [Swift]LeetCode104. 二叉树的最大深度 | 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] 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 104. Maximum Depth of Binary Tree
Problem: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along ...
- [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 ...
- Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference
最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...
- [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:Maximum Depth of Binary Tree_104
LeetCode:Maximum Depth of Binary Tree [问题再现] Given a binary tree, find its maximum depth. The maximu ...
随机推荐
- django自带分页代码
django分页 {% if is_paginated %} <div class="pagination-simple"> <!-- 如果当前页还有上一页,显示 ...
- 【51NOD-0】1019 逆序数
[算法]离散化+树状数组(求逆序对) [题解]经典,原理是统计在i之前插入的且值≤i的个数,然后答案就是i-getsum(i) #include<cstdio> #include<a ...
- 【BZOJ】2502 清理雪道
[算法]有源汇上下界最小流 [题解]上下界 初看以为是最小覆盖,发现边可以重复经过,不对. 要求所有边都经过……那就下界为1,上界为inf的可行流. 源汇……S连入度为0的点,T连出度为0的点?(反正 ...
- NightMare2(SCU4527+dijkstra+二分)
题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4527 题目: 题意:最短路的每条边除了边权之外还会有一个限制(财富,身上带的财富大于这个值则不能通 ...
- php中比较好用的函数
PHP中一个好用的函数parse_url,特别方便用来做信息抓取的分析,举例子如下: $url = "http://www.electrictoolbox.com/php-extract-d ...
- 01背包入门 dp
题目引入: 有n个重量和价值分别为Wi,Vi的物品.从这些物品中挑选出总重量不超过W的物品,求所有挑选方案中的价值总和的最大值. 分析: 首先,我们用最普通的方法,针对每个物品是否放入背包进行搜索. ...
- Less & Sass
CSS不是一种编程语言.它开发网页样式,但是没法用它编程.也就是说,CSS基本上是设计师的工具,它没有变量,也没有条件语句,只是一行行单纯的描述.有人就开始为CSS加入编程元素,这被叫做"C ...
- css3_box-shadow使用记录
1.box-shadow这个属性有6个参数可设置,使用的时候比较少用,每次使用的时候都会忘记,故写此文作记录. 样式: /*1.添加此属性添加阴影*/ box-shadow: 0 0 10px 10p ...
- 如何入门 Python 爬虫?
作者:谢科 来源:知乎链接:https://www.zhihu.com/question/20899988/answer/24923424 著作权归作者所有.商业转载请联系作者获得授权,非商业转载 ...
- python进行机器学习(一)之数据预处理
一.加载数据 houseprice=pd.read_csv('../input/train.csv') #加载后放入dataframe里 all_data=pd.read_csv('a.csv', h ...