leetcode 572. Subtree of Another Tree(判断子树)

LeetCode --- 572. Subtree of Another Tree 解题报告 Given two non-empty binary treessandt, check whether treethas exactly the same structure and node values with a subtree ofs. A subtree ofsis a tree consists of a node insand all of this node... 阅读详情

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’s descendants. The tree s could also be considered as a subtree of itself.

Example 1:
Given tree s:

     3
    / \
   4   5
  / \
 1   2

Given tree t:

   4 
  / \
 1   2

Return true, because t has the same structure and node values with a subtree of s.

给出两棵二叉树s和t, 判断t是不是s的子树。

思路:
用到了相同树的判断,如果不是相同的树,就进一步判断t 在s的左子树,右子树中有没有相同的树

    public boolean isSubtree(TreeNode s, TreeNode t) {
        if(s == null) return false;
        if(isSame(s, t)) return true;
        return isSubtree(s.left, t) || isSubtree(s.right, t);
    }
    
    boolean isSame(TreeNode s, TreeNode t) {
        if(s == null && t == null) return true;
        if(s == null || t == null) return false;
        if(s.val == t.val) return isSame(s.left, t.left) && isSame(s.right, t.right);
        return false;
    }
yolov11模型训练步骤 YOLOv11训练步骤:①配置GPU环境;②标注数据并划分训练/验证/测试集(8:1:1);③创建YAML文件配置数据集路径及类别;④按硬件条件选择预训练模型(n/s/m/l/x);⑤设定类别数后启动训练,核心参数含学习率(0.001)、Adam优化器、批次大小(16-64)及数据增强策略(翻转/mixup),启用早停机制;⑥训练后使用测试集验证,通过混淆矩阵、PR曲线评估模型性能,优化置信度阈值提升检测精度。全流程注重硬件资源与模型效能的平衡。 阅读详情

相关推荐

SAR成像系列:【3】合成孔径雷达(SAR)的二维回波信号与简单距离多普勒(RD)算法 (附matlab代码)

二维回波信号分析

zr2006_7的专栏 2万+

【Leetcode刷题笔记】572. Subtree of Another Tree判断一个树是否是另一个树的子树

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node...

知吾朱期应庆的博客 353

实战教程:如何用Python+小波变换+CNN搞定医学影像中的条纹噪声(附完整代码)

本文提供了一套完整的实战方案,指导如何利用Python结合小波变换与卷积神经网络(CNN)去除医学影像中的条纹噪声。该方法通过小波变换精准定位噪声,再使用轻量化CNN进行针对性清除,有效保护图像细节,并附有可运行的完整代码,为医学影像处理与AI分析提供高效工具。

weixin_29056101的博客 285

LeetCode //C - 572. Subtree of Another Tree

【代码】LeetCode //C - 572. Subtree of Another Tree。

Made in Code 1997

一个Skill告别AI废话:4.3万Star的Agent行为约束实战指南

在AI编程工具中,大语言模型常因对齐训练和缺乏输出契约而产生冗余解释与过度确认。Agent Skill作为一种可复用的行为指令集,通过角色锚定、任务边界、输出格式契约和边界处理规则,将模型从聊天机器人收敛为执行单元。其技术价值在于提升输出纪律性与可控性,适用于CodeX、Claude Code、GitHub Copilot等场景,解决AI废话痛点。本文围绕一个获4.3万Star的开源Skill项目,拆解其机制、实操与定制思路。

weixin_42524499的博客 292

IIR数字滤波器原理,设计方法及嵌入式应用

基于STM32的二阶直接II型巴特沃斯低通滤波器设计方法及应用

weixin_38342580的博客 1万+

[LeetCode]572. Subtree of Another Tree(判断树t是否是树S的子树)

572. Subtree of Another Tree原题链接 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of

whl_program的博客 1180

第6章: MMU Notifier在KVM虚拟化中的应用

本文分析了KVM如何利用MMU Notifier机制维护客户机与宿主机地址映射一致性。KVM采用三层地址空间转换架构(GVA→GPA→HPA),通过硬件辅助虚拟化(EPT/NPT)实现高效转换。重点探讨了KVM MMU Notifier回调实现,包括invalidate_range_start/end等核心函数,以及HVA范围处理流程。当宿主机内存变化时,KVM通过注册的notifier回调及时更新映射关系,确保虚拟化环境的内存一致性。文章详细解析了相关数据结构和关键代码实现,揭示了KVM内存管理的核心机制

图形/计算GPU的驱动与虚拟化技术分享园地 2361

leetcode 572. Subtree of Another Tree 子树判断 + 深度优先遍历DFS

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node...

JackZhangNJU的专栏 265

Vue3 - 手机移动端H5网页强力解决弹起软键盘后页面被挤压变形或页面整体上移问题,点击input输入框键盘弹出底部被上推往上顶遮挡及各种问题(兼容安卓苹果ios手机,微信公众号网页微信内置浏览器)

vue3,h5网页,input输入框组件,vue3 h5软键盘弹出,vue3输入框,键盘弹起时页面整体上移问题,uni,H5页面,解决软键盘弹起页面被挤压、被往顶的问题,解决vue3输入框,键盘弹起时页面整体上移问题,vue3调用手机系统软键盘,页面窗口被顶起,布局定位失效,解决VUE3软键盘弹起导致页面fixed定位元素被顶上去,输入法软键盘弹起,窗口顶起,变形解决办法,Vue中input组件在IOS设备上弹出软键盘时页面整体上移问题的解决方案,以及input组件聚焦后弹出软键盘固定在,Vue3软键盘把界

🏆 前端领域优质创作者 1万+

【一 扣子客户案例合集】【 1.3 识典古籍基于扣子智能助手的古籍数字化全流程技术解析】

古籍数字化智能处理系统全流程解析 本文详细介绍了基于扣子智能助手的古籍数字化解决方案,核心技术包括: 多层级架构设计:采用"云-边-端"三层次架构,整合高精度扫描设备与AI处理模块,实现从物理古籍到结构化数据的全流程自动化。 智能图像处理:通过12道预处理工序(包括畸变校正、污渍去除和对比度增强)处理古籍图像,采用改进的EAST算法和ViT模型实现高精度文字检测与识别,准确率达98.7%。 NLP增强处理:结合Transformer-XL预训练模型和N-gram语言模型进行文本校正,基于

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 1455

树的递归写法

树的相关递归写法 将树分为三部分,根节点,左子树, 右子树,分别判断情况 递归出口, 判断是return false 还是return true; 根节点满足某种条件 return 递归(左子树) && 递归(右子树) 满足某种条件 或者 return 递归(左子树) || 递归右子树 只要有一边满足条件即可 return false 100. Same Tr...

qq_28350997的博客 5430

中台战略-第五章、中台建设方法论

文章目录第五章、中台建设方法论5.1 中台架构整体策略5.2 业务顶层设计5.3 业务中台设计方法论5.3.1 能力支撑是基础5.3.2 中心自治是承载形式5.3.3 3层模型是骨架5.3.4 5步法是指导思想1. 业务抽象2. 高阶设计3. 组件建模4. 开发交付5. 持续运营5.4 数据中台设计方法论5.4.1 总体规划5.4.2 数据集成5.4.3 模型建设5.4.4 通用研发5.4.5 资产管理5.4.6 数据服务5.5 应用向中台迁移的3中途径和方法5.5.1 方法1:新应用替换旧应用5.5.2

沧海之巅的专栏 1466

[leetcode] 572. Subtree of Another Tree @ python

原题 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this n...

闲庭信步 500

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

572. Subtree of Another Tree*

572. Subtree of Another Tree* https://leetcode.com/problems/subtree-of-another-tree/ 题目描述 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values ...

珍妮的选择的博客 257

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

leetcode 572 Subtree of Another Tree (子树)

题目描述 给定两个非空的二叉树s和t,检查树t的结构和节点值是否和s的一个子树完全相同。s的子树是由s中的一个节点和该节点的所有后代组成的树(一直到根节点)。树S也可以被认为是它自己的子树。 主要代码c++ /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *...

爱喝舒化奶的博客 380

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Leetcode572 Subtree of Another Tree解题方案

Leetcode572 Subtree of Another Tree 题目描述 Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’s descendants.

初七的博客 163

【LeetCode & 剑指offer刷题】树题8:26 树的子结构(572. Subtree of Another Tree)

【LeetCode & 剑指offer刷题】树题8:26 树的子结构(572. Subtree of Another Tree) 【LeetCode & 剑指offer 刷题笔记】目录(持续更新中...) 572. Subtree of Another Tree Given two non-empty binary trees ...

技术改变世界 826

【Leetcode】572. Subtree of Another Tree

求一棵树是不是另一棵树的子树 方法1 双递归 对母树的每个节点进行访问,判断以该节点为定点的树是不是和子树相同 class Solution1: def isSubtree(self, s, t): """ :type s: TreeNode :type t: TreeNode :rtype: bool ""...

很吵请安静 466

LeetCode572:Subtree of Another Tree

Given two non-empty binary treessandt, check whether treethas exactly the same structure and node values with a subtree ofs. A subtree ofsis a tree consists of a node insand all of this node...

卷卷萌的博客 320

[LeetCode][572] Subtree of Another Tree题解

[LeetCode][572] Subtree of Another Tree题解 题意:给一个树t和s,判断在t中是否有一个子树s。 思路: dfs遍历一个树把t和s的val值一样的节点加入treenode*型的vector中,再使用搜索判断这个节点x开始,x和s是否一模一样,这里使用dfs来写isSame 代码 /* * [572] Subtree of Another Tree ...

OCEANtroye的博客 318

LeetCode-572. Subtree of Another Tree [C++][Java]

Given the roots of two binary treesrootandsubRoot, returntrueif there is a subtree ofrootwith the same structure and node values ofsubRootandfalseotherwise. A subtree of a binary treetreeis a tree that consists of a node intreeand all of th...

贫道绝缘子的博客 374

Leetcode 572. Subtree of Another Tree (python+cpp)

Leetcode 572. Subtree of Another Tree题目解法:双层递归 题目 解法:双层递归 虽然这道题目标的easy,但是其实蛮考对于递归的理解的。最直观的解法是双层递归,外层递归遍历节点,内层递归判断当前遍历的节点形成的子树是否与目标树相同。外层循环只要有一个节点符合情况即可,二内层循环需要每个节点都相同才行 python: class Solution: def isSubtree(self, s: TreeNode, t: TreeNode) -> bool:

qq_37821701的博客 351

572. 另一个树的子树(subtree-of-another-tree)递归思维解答

572. 另一个树的子树(subtree-of-another-tree) 题目 给定两个非空二叉树 s 和 t,检验 s 中是否包含和 t 具有相同结构和节点值的子树。s 的一个子树包括 s 的一个节点和这个节点的所有子孙。s 也可以看做它自身的一棵子树。 示例 1: 给定的树 s: 3 / \ 4 5 / \ 1 2 给定的树 t: 4 / ...

mirana的专栏 403

LeetCode-572. Subtree of Another Tree (JAVA)子树

LeetCode-572. Subtree of Another Tree (JAVA)子树

mine_song的博客 2115

[LeetCode] 572. Subtree of Another Tree

原题链接:

Ber03的博客 261
上一篇: leetcode 563. Binary Tree Tilt(二叉树的倾斜度)
下一篇: leetcode 617. Merge Two Binary Trees(合并2棵二叉树)
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址