当前位置:网站首页>104.二叉树的最大深度
104.二叉树的最大深度
2022-07-26 10:42:00 【Forest_1010】
题目:给定一个二叉树,找出其最大深度。
先求它的左子树的深度,再求的右子树的深度,最后取左右深度最大的数值 再+1。
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */
class Solution {
public:
int maxDepth(TreeNode* root) {
if(root==NULL) return 0;
return 1+max(maxDepth(root->left),maxDepth(root->right));
}
};
层次遍历
边栏推荐
- Application of.Net open source framework in industrial production
- 文案秘籍七步曲至----文献团队协作管理
- 第7期:内卷和躺平,你怎么选
- 第5期:大学生入职必备技能之二
- .net operation redis list list
- Dry goods likeshop takeout order system is open source, 100% open source, no encryption
- Koin
- Redis implementation of distributed lock solution
- Write to esp8266 burning brush firmware
- Flutter jni混淆 引入.so文件release包闪退
猜你喜欢

RT-Thread 学习笔记(五)---编辑、下载、调试程序
![[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)](/img/94/ff52b043320b6dea5ca1238e314de8.png)
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)

Flutter编译报错 version of NDK matched the requested version 21.0.6113669. Versions available locally: 2
![Error[pe147]: declaration is incompatible with 'error problem](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[pe147]: declaration is incompatible with 'error problem

SAP ABAP 守护进程的实现方式

GIS方法类期刊和论文的综述(Introduction)怎么写?

Analysis of the transaction problem of chained method call

Problems encountered in QRcode QR code (C language)

Disable usbjatg in Altium Designer

【机器学习小记】【人脸识别】deeplearning.ai course4 4th week programming
随机推荐
Flutter集成极光推送
Redis implementation of distributed lock solution
鹏哥C语言——扫雷2021-08-16
C语言鹏哥20210812C语言函数
Anaconda is used on vscode (the environment has been configured)
RT thread learning notes (VIII) -- start the elmfat file system based on SPI flash (Part 2)
使用float实现左中右布局,中间内容自适应
反射机制简述
剑指Offer(九):变态跳台阶
Error[pe147]: declaration is incompatible with 'error problem
使用定位实现左中右布局,中间内容自适应
剑指Offer(四十九):把字符串转换成整数
RT-Thread 学习笔记(一)---配置RT-Thread开发环境
剑指Offer(八):跳台阶
(转载)ArcGIS Engine中各种点的创建方法
RT thread learning notes (I) -- configure RT thread development environment
winpcap 抓包函数pcap_loop(),停止问题
Common classes (understand)
.net operation redis list list
[dectectron2] follow the official demo