当前位置:网站首页>LeetCode-104-二叉树的最大深度
LeetCode-104-二叉树的最大深度
2022-06-11 21:23:00 【z754916067】
题目

思路
- 差不多 还是递归
代码
public int maxDepth(TreeNode root) {
if(root==null) return 0;
int ans1=1;
int ans2=1;
if(root.left!=null) ans1 = Depth(root.left,1);
if(root.right!=null) ans2 = Depth(root.right,1);
return Math.max(ans1,ans2);
}
public int Depth(TreeNode root,int depth){
int ans1=depth;
int ans2=depth;
if(root.left!=null) ans1=Depth(root.left,depth+1);
if(root.right!=null) ans2=Depth(root.right,depth+1);
return Math.max(Math.max(ans1,ans2),depth+1);
}
边栏推荐
- 【C语言进阶】整型在内存中的存储
- Cuckoo Hash
- Common file functions
- Codeforces Round #739 (Div. 3)解题报告
- AC自动机
- JVM运行时常量池以及直接内存
- Only 38 years old! Zhou Chuan, a researcher of the Chinese Academy of Sciences, died unfortunately. Rao Yi sent a document to mourn: he guided me when he was still my student
- 数据库每日一题---第9天:销售员
- Solve the problem of img 5px spacing
- MySQL add adds multiple new fields and specifies the field location
猜你喜欢

SQL的语法

使用 float 创建一个网页页眉、页脚、左边的内容和主要内容。

Syntax of SQL

Part II data link layer

Why is your LDO output unstable?

JVM object allocation policy TLAB

2021牛客多校5 Double Strings

LabVIEW控制Arduino实现超声波测距(进阶篇—5)
![[Part 15] use and basic principle of forkjoinpool [key]](/img/36/e21b16ec92d444149bc793f340f9f3.jpg)
[Part 15] use and basic principle of forkjoinpool [key]

Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
随机推荐
Goto statement of go language
What are striplines and microstrip lines? Reference planes and transmission lines
bzoj3188 Upit
Explanation of each column output by explain statement
JMeter load test finds the maximum number of concurrent users (including step analysis)
Jenkins+allure integrated report construction
ORA-04098: trigger ‘xxx. xxx‘ is invalid and failed re-validation
Codeforces Round #740 Div. 2 解题报告
CANN编码的一些报错汇编
Simple classification example of brain cell membrane equivalent neural network
The gateway starts other microservices first. When the gateway is started, the gateway cannot be started and there is no exception log; Start the gateway first, and all services can be started normall
Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
ORA-04098: trigger ‘xxx.xxx‘ is invalid and failed re-validation
Only 38 years old! Zhou Chuan, a researcher of the Chinese Academy of Sciences, died unfortunately. Rao Yi sent a document to mourn: he guided me when he was still my student
Codeforces Round #742 (Div. 2) F. One-Four Overload
Answer fans' questions | count the number and frequency of letters in the text
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]
JVM|虚拟机栈(局部变量表;操作数栈;动态链接;方法的绑定机制;方法的调用;方法返回地址)
LeetCode-322-零钱兑换
作为一名 ABAP 资深顾问,下一步可以选择哪一门 SAP 技术作为主攻方向?