From d5cb5fbc31905039e5c401113f1f553666788c5a Mon Sep 17 00:00:00 2001 From: CyC2018 Date: Wed, 28 Oct 2026 13:45:04 +0800 Subject: [PATCH] =?UTF-8?q?Update=2026.=20=E6=A0=91=E7=9A=84=E5=AD=90?= =?UTF-8?q?=E7=BB=93=E6=9E=84.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。 --- notes/26. 树的子结构.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/notes/26. 树的子结构.md b/notes/26. 树的子结构.md index bce9fbf9..26e2229d 100644 --- a/notes/26. 树的子结构.md +++ b/notes/26. 树的子结构.md @@ -2,7 +2,7 @@ ## 题目链接 -[牛客网](https://www.nowcoder.com/practice/6e196c44c7004d15b1610b9afca8bd88?tpId=13&tqId=11170&tPage=1&rp=1&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking&from=cyc_github) +[Leetcode](https://leetcode.cn/problems/shu-de-zi-jie-gou-lcof/) ## 题目描述 @@ -11,10 +11,10 @@ ## 解题思路 ```java -public boolean HasSubtree(TreeNode root1, TreeNode root2) { - if (root1 == null || root2 == null) +public boolean isSubStructure(TreeNode A, TreeNode B) { + if (A == null || B == null) return false; - return isSubtreeWithRoot(root1, root2) || HasSubtree(root1.left, root2) || HasSubtree(root1.right, root2); + return isSubtreeWithRoot(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B); } private boolean isSubtreeWithRoot(TreeNode root1, TreeNode root2) {