Leetcode---Symmetric Tree

leetcode之symmetric-tree(判断二叉树是否是镜像二叉树) leetcode之symmetric-tree(判断二叉树是否是镜像二叉树) 题目 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: But the following ... 阅读详情

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

For example, this binary tree is symmetric:

    1
   / \
  2   2
 / \ / \
3  4 4  3


But the following is not:

    1
   / \
  2   2
   \   \
   3    3


判断一棵树是不是镜像。关于树,直接的想法就是递归,但是这个题目从单个树来看是无法递归的,但是可以用两个树来递归。


  1. bool f(TreeNode * l, TreeNode * r){
  2.     if(l==NULL && r==NULL)
  3.         return true;
  4.     if(l==NULL || r==NULL)
  5.         return false;
  6.     return l->val==r->val && f(l->left,r->right)&&
  7.         f(l->right,r->left);
  8. }
  9. bool isSymmetric(TreeNode *root) {
  10.     if(root==NULL)
  11.         return true;
  12.     return f(root->left,root->right);
  13. }



<script>window._bd_share_config={"common":{"bdsnskey":{},"bdtext":"","bdmini":"2","bdminilist":false,"bdpic":"","bdstyle":"0","bdsize":"16"},"share":{}};with(document)0[(getelementsbytagname('head')[0]||body).appendchild(createelement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new date()/36e5)];</script>
阅读(7) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
1.2、基于卷积神经网络(CNN)的车牌自动识别系统(matlab) 基于卷积神经网络(CNN)的车牌自动识别系统(matlab) 阅读详情

相关推荐

从零构建:四轴机械臂D-H参数建模与MATLAB实战指南

本文详细介绍了四轴机械臂D-H参数建模的完整流程与MATLAB实战应用。从机械臂运动学基础出发,解析D-H参数原理与坐标系建立规则,提供MATLAB Robotics Toolbox的安装、模型创建及正逆运动学求解的代码实现。特别针对四轴机械臂的逆运算优化、轨迹规划和奇异位形规避等高级应用给出实用解决方案,是机器人开发者的实战指南。

weixin_29062255的博客 419

闯关leetcode——101. Symmetric Tree

这题是检验树是否按中间线镜像。如果翻译成计算机语言,就是对比左子树中节点下的左子树和右子树中节点下的右子树是否一致。只有对比到最后一层都是nullptr时,才能说明子树一致,而数值或结构不一致都认为不一致。

方亮的专栏 606

拥有AI助手便能解放双手?——抖音直播脚本的生成

科技改变生活,AI助手帮你完成抖音创作!

Scientist_的博客 2352

leetcode 之 Symmetric Tree 镜像树

Symmetric Tree

fangjian1204的专栏 2161

【OpenSearch】从零到一:手把手搭建OpenSearch与Dashboard可视化平台

本文提供了一份详细的OpenSearch与Dashboard可视化平台从零搭建指南。内容涵盖环境准备、系统调优、核心服务安装配置、Dashboard部署与汉化,以及生产环境安全加固建议,帮助用户快速构建一个功能完整的搜索与分析平台。

devops8pract的博客 617

SmsForwarder v6.4.0 + Flask API 实战:5步搭建手机验证码自动化接收服务

本文详细介绍了如何利用SmsForwarder v6.4.0和Flask API构建企业级验证码自动化处理系统。通过5个关键步骤,包括系统架构设计、Android端配置、Flask服务端实现、企业级部署方案以及实战应用场景扩展,帮助开发者高效处理短信验证码,提升自动化测试和数据采集的工作效率。

weixin_30292745的博客 392

入坑LeetCode: 101. Symmetric Tree

入坑LeetCode: 101. Symmetric Tree 1、解题思路 判断一棵二叉树是否对称,其实就是递归判断,层层判断,将左二子与右儿子比较,将左二子的右儿子与右儿子的左二子比较,如果始终相同,则返回true。 2、代码 bool isymmetric(struct TreeNode* left,struct TreeNode* right){ if(left == NULL &...

chicwzh的博客 257

YOLOv11 改进 - SPPF模块 | 发论文神器!LSKA注意力改进SPPF,增强多尺度特征提取能力,高效涨点!!!

本文介绍了Large Separable Kernel Attention (LSKA)模块及其在YOLOv11中的结合应用。LSKA旨在解决Visual Attention Networks (VAN)使用大内核卷积时的计算效率问题,通过将2D深度卷积层的卷积核分解为级联的水平和垂直1-D卷积核,降低了计算复杂度和内存占用,且使VAN更关注物体形状。我们将集成LSKA的SPPF_LSKA模块引入YOLOv11,大量实验表明,改进后的模型在对象识别、检测、分割和稳健性测试上表现出色。

魔改工程师的博客 1279

LeetCode 101. Symmetric Tree 题解

本题是二叉树的经典问题,主要考察对树的对称性的理解和遍历方法的应用。递归深度优先搜索:代码简洁易懂,逻辑清晰,是最直观的解决方案。迭代广度优先搜索:避免了递归的栈溢出问题,适用于深度较大的树。在实际应用中,递归方法通常是最首选的解决方案,因为它代码简洁且易于理解。但在处理深度较大的树时,迭代方法可能更为可靠。无论使用哪种方法,核心思想都是相同的:检查二叉树的左子树和右子树是否是镜像对称的。

cannonjinx的博客 2007

Level 4自动驾驶系统设计0——功能与场景0

摘要:当前智能驾驶系统开发存在应试思维误区,过度依赖NCAP标准测试而忽视真实物理世界的复杂工况。随着系统进入L4大模型时代,必须从离散测试转向应对无限连续的长尾场景。关键在于解决传感器输入质量(避免"垃圾进垃圾出"问题),通过逆向定义方法论确保前端数据高置信度。同时采用影子模式收集分歧数据流,结合条件接受机制动态调整感知权重,最终实现功能释放主权(FO)的100%安全闭环。本文揭示了如何为端到端智驾大模型建立物理红线,这是确保L4系统量产的底层法则。

Godspeed_zwh的博客 307

Ubuntu22.04安装ros(一键搞定)

然后发现可以一键安装,话不多说,直接终端输入如下指令。回车之后系统会自动安装ros。

m0_47313541的博客 7413

leetcode 101. Symmetric Tree\100. Same Tree\572. Subtree of Another Tree

【代码】leetcode 101. Symmetric Tree\100. Same Tree\572. Subtree of Another Tree。

weixin_41554427的博客 525

哨兵1号回波数据(L0级)FDBAQ压缩算法详解

本文介绍哨兵1号用的FDBAQ算法,它实现非整数可变bit压缩,大部分数据仅需 3bit输出,少数高反射率数据需4bit输出,使得平均输出比特率刚超过3bit,比熵约束分块自适应量化 (ECBAQ)压缩算法所需的3.7bit更低。也就是说FDBAQ压缩完,除了要记录分块尺寸和各块的均值码(对应哨兵1号数据包里的THIDX)外,还需要记录霍夫曼码字的长度(对应哨兵1号数据包里的BRC)。唯一不同的就是量化后的编码规则使用了霍夫曼编码,相当于在传统的BAQ压缩流程的后面又加了一个步骤。

2302

LeetCode 101. Symmetric Tree

LeetCode 101. Symmetric Tree Solution1 参考《剑指offer》上的解法:https://blog.youkuaiyun.com/allenlzcoder/article/details/79769550 /** * Definition for a binary tree node. * struct TreeNode { * int val; * ...

Allenlzcoder的博客 353

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

LeetCode Top 100 Liked Questions 101. Symmetric Tree (Java版; Easy)

welcome to my blog LeetCode Top 100 Liked Questions 101. Symmetric Tree (Java版; Easy) 题目描述 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, ...

littlehaes的博客 149

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

LeetCode 力扣 101. 对称二叉树 symmetric tree DFS

大家觉得写还可以,可以点赞、收藏、关注一下吧! 也可以到我的个人博客参观一下,估计近几年都会一直更新!和我做个朋友吧!https://motongxue.cn 文章目录101. 对称二叉树进阶:分析提交结果 101. 对称二叉树 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ 2 2 / \ / \ 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1

motongxue的博客 206

leetcode笔记 100. Same Tree & 101. Symmetric Tree

leetcode刷题14天 100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes ha...

qq_29868413的博客 238

Leetcode之Symmetric Tree

题目: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree[1,2,2,3,4,4,3]is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 ...

qq_35455503的博客 203

LeetCode101—Symmetric Tree

LeetCode101—Symmetric Tree 判断一棵树是否对称

上善若水 769

LeetCode 101. Symmetric Tree(二叉树)

题目来源:https://leetcode.com/problems/symmetric-tree/ 问题描述 101.Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this b...

da_kao_la的博客 156

LeetCode力扣 101. 对称二叉树 Symmetric Tree 题解代码 JavaScript

https://leetcode-cn.com/problems/symmetric-tree/ /** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } */ /** * @param {TreeNode} root * @return {boolean} */ function i

Coding home - 漂流瓶jz 460

Leetcode Symmetric Tree Python 学习递归/DFS/BFS

Leetcode 101题 Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2...

润泽的博客 260

LeetCode: Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

Tingmei的专栏 2369

[leetcode]Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the f

tuantuanls的专栏 690

leetcode_symmetric-tree

题目链接 https://leetcode-cn.com/problems/symmetric-tree/ 题目内容 给定一个二叉树,检查它是否是镜像对称的。 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / 2 2 / \ / 3 4 4 3 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / 2 2 \ 3 3 进阶: 你可以运用递归和迭代两种方法解决这个问题吗? 解题思路 1.若是空树或者是只有一个节点的树则返回tru

weixin_38554391的博客 175
上一篇: 如何正确的写出二分查找算法
下一篇: Leetcode---Maximum Depth of Binary Tree
我把葡萄酿成酒
博客等级 码龄12年 275粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值