当前位置:网站首页>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);
}
边栏推荐
- Syntax of SQL
- Notes on the preload method of Gorm
- JVM之对象创建过程
- LeetCode-43-字符串相乘
- [game theory complete information static game] strategic game
- Release of version 5.6 of rainbow, add multiple installation methods, and optimize the topology operation experience
- RANSAC extraction plane (matlab built-in function)
- apache 本地多端口配置
- RANSAC提取平面(MATLAB内置函数)
- As a senior abap consultant, which SAP technology can be selected as the main direction in the next step?
猜你喜欢

Goto statement of go language

【C语言进阶】整型在内存中的存储

第一部分 物理层

【C語言進階】整型在內存中的存儲
![Analysis on the development history and market development status of China's system integration industry in 2020 [figure]](/img/3c/b53c2a3f59ff6784f128cb98a5a7a2.jpg)
Analysis on the development history and market development status of China's system integration industry in 2020 [figure]

The official announced the launch of Alibaba's 2023 global school recruitment: Technical Posts account for more than 60%

Which Bluetooth headset is better within 500? Inventory of gifts for girls' Day

Database daily question --- day 9: salesperson

Apache local multi port configuration

What are striplines and microstrip lines? Reference planes and transmission lines
随机推荐
正则校验匹配[0-100]、[0-1000]之间的正整数或小数点位数限制
How to Load Data from CSV (Data Preparation Part)
LeetCode-76-最小覆盖子串
Notes on the preload method of Gorm
使用 float 创建一个网页页眉、页脚、左边的内容和主要内容。
12 golden rules of growth
【博弈论-完全信息静态博弈】 战略式博弈
Three waves of changes in cloud computing
线性表的链式存储结构
A collection of commonly used open source data sets for face recognition
apache 本地多端口配置
JVM之堆区
Go语言for循环
JVM方法区
Tensorflow 2. X Getting Started tutorial
Codeforces Round #740 Div. 2 解题报告
JS performs non empty judgment on various data types of the returned data.
Explanation of each column output by explain statement
可综合RTL代码设计方法和注意事项
AC自动机