当前位置:网站首页>【力扣】对称二叉树
【力扣】对称二叉树
2022-07-17 05:13:00 【Patrick star`】
题目:
给你一个二叉树的根节点 root , 检查它是否轴对称。

思路:
不看根结点,将一个树看成两棵树,如果是对称二叉树,一个树的左孩子等于另一个树的右孩子
代码:
bool isSymTree(struct TreeNode* p, struct TreeNode* q){
if(p==NULL && q==NULL)
{
return true;
}
if(q==NULL || p == NULL)
{
return false;
}
if(p->val != q->val)
{
return false;
}
bool ret1 = isSymTree(p->left,q->right);//比较p的左子树与q的右子树
bool ret2 = isSymTree(p->right,q->left);//比较p的右子树与q的左子树
return ret1 && ret2;
}
bool isSymmetric(struct TreeNode* root){
if(root == NULL)
{
return true;
}
return isSymTree(root->left,root->right);//比较左右子树
}边栏推荐
- Vscode configuring golang development environment
- Minio installation, deployment and simple use
- 數學基礎課2_歐拉函數,線性篩,擴歐
- golang 多项目工作区搭建
- 热电阻pt100 CU50隔离转换器转4-20ma模拟量输出温度变送器0-10V
- Acwing第58场周赛(AK)
- 简单Chrome脚本 自动跳过b站视频播放结束后的的充电鸣谢页面
- 2021-11-26 pyautogui cooperates with lightning simulator to realize the automation of mobile app check-in and answer questions
- Fs4061a (5V USB input, double lithium battery series application, 5V boost charging, 8.4v Management IC
- uboot 编译前的配置命令make config分析
猜你喜欢

索引库中的文档的操作

2021-09-15

设置索引库结构,给用户添加可自动补全的suggestion,并将一些字段变成集合放到suggestion里面去

Configure the 'log' shortcut key in vscode and remove the console log(‘‘); Semicolon in;

2021-11-17 esp32 pin reference

处理中文分词 ik分词器以及拓展和停止字典

Fs68001 wireless charging SOC chip has simple periphery and schematic diagram of 5W wireless charging scheme

RestClient查询文档

Hm9922 switching buck LED constant current driver IC

【力扣】另一棵树的子树
随机推荐
Antd is not defined
串口循环缓存区 简单 免初始化 不用堆、指针、分段memcpy
Solve cannot read properties of null (reading 'pickalgorithm')
HM agent multi section lithium battery charging IC
MySQL workbench basically uses [create a database]
Pressure strain bridge signal processing photoelectric isolation amplifier
Darwin's analytical experience
宽电压输入高电压输出 电压控制型
Hra2460d-2w high voltage power supply high voltage module - high voltage - high precision hra2460d-2w
Ehab the Xorcist (异或性质,构造)
带透明png转换成c数组
busybox date 时间的加减
Configure the 'log' shortcut key in vscode and remove the console log(‘‘); Semicolon in;
【力扣】单值二叉树
Cours de mathématiques de base 2 Fonction Euler, écran linéaire, élargissement de l'Europe
Simple chrome script automatically skips the charging acknowledgment page after the video playback of station B ends
4-20mA to 0-5khz, 5V pulse converter
4路编码器脉冲计数器,8路DO,Modbus TCP模块
[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....
【力扣】二叉树的前序遍历