当前位置:网站首页>【力扣】二叉树的最大深度
【力扣】二叉树的最大深度
2022-07-17 05:13:00 【Patrick star`】
题目:
给定一个二叉树,找出其最大深度。
二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。
说明: 叶子节点是指没有子节点的节点
思路:
利用先序遍历,每递归一层深度+1
代码:
int maxDepth(struct TreeNode* root)
{
if(root == NULL)
{
return 0;
}
int ldepth = maxDepth(root->left);//左子树的高度
int rdepth = maxDepth(root->right);//右子树的高度
return ldepth > rdepth ? ldepth + 1:rdepth + 1;
}边栏推荐
- Qtss callback routine
- 解决Cannot read properties of null (reading ‘pickAlgorithm‘)
- busybox 指定日期修改 暂时不需要clock -w 写入硬件
- MySQL Workbench基本使用 【创建一个数据表】
- Loadng class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdb
- MCU single chip OTP
- BusyBox 1.21.1 有udpsvd功能 可以编译成功 不干涉本机busybox方法
- QTSS常数
- DSL实现自动补全查询
- golang高并发特性goroutine介绍
猜你喜欢

LTH7五脚芯片的完整方案图FS4054充电电路原理

Chrome浏览器设置 【显示右上角 翻译语言图标】

RestClient-多条件聚合

vscode 配置golang开发环境

Wireless charging mouse pad RGB LED lighting wireless charging mouse pad
![Vscode instant English translation plug-in [translation (English Chinese Dictionary)]](/img/f4/9bd90910fef061b423ea8309fab439.png)
Vscode instant English translation plug-in [translation (English Chinese Dictionary)]

FS68001无线充SOC芯片外围简单,5W无线充方案原理图

升高压模块隔离模块HRA2460D-2W

Darwin Streaming Server 介绍

0-10V,4-20mA电流电压转PWM隔离转换器 质料以及应用电路图
随机推荐
XOR-gun (位运算,思维,区间暴力)
busybox date 日期增加一天明天 网上都是减一天 昨天
2021-09-15
golang高并发特性goroutine介绍
计算几何(2)
MCU单片机OTP
MCU single chip OTP
4-20mA to 4-20mA 0-5V to 0-5V analog signal isolation transmitter
Fs68001 wireless charging SOC chip has simple periphery and schematic diagram of 5W wireless charging scheme
Configure the 'log' shortcut key in vscode and remove the console log(‘‘); Semicolon in;
TP4054充电IC使用技巧---配合中科蓝讯AB5365B使用
Introduction to basic knowledge of Minio
[BJOI2019] 排兵布阵(分组背包)
Darwin分析经验
RestAPI实现自动补全 & 案例实现(搜索框输入进行自动补全)
Speed sensor signal isolation, acquisition and transformation, sine wave and sawtooth wave signal input, square wave signal output, signal converter
Pressure strain bridge signal processing photoelectric isolation amplifier
Rs-485/232 to 4-20ma/0-10v isolated d/a converter
4路编码器脉冲计数器,8路DO,Modbus TCP模块
Loadng class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdb