Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f431398

Browse files
fix: update solution to lcof problem: No.26 (#3757)
1 parent 188f9ac commit f431398

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎lcof/面试题26. 树的子结构/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ edit_url: https://github.com/doocs/leetcode/edit/main/lcof/%E9%9D%A2%E8%AF%95%E9
6060

6161
1. 如果树 B 为空,则树 B 是树 A 的子结构,返回 `true`;
6262
2. 如果树 A 为空,或者树 A 的根节点的值不等于树 B 的根节点的值,则树 B 不是树 A 的子结构,返回 `false`;
63-
3. 判断树 A 的左子树是否包含树 B,即调用 $\textit{dfs}(A.left, B),ドル并且判断树 A 的右子树是否包含树 B,即调用 $\textit{dfs}(A.right, B)$。如果其中有一个函数返回 `false`,则树 B 不是树 A 的子结构,返回 `false`;否则,返回 `true`
63+
3. 判断树 A 的左子树是否包含树 B 的左子树,即调用 $\textit{dfs}(A.left, B.left),ドル并且判断树 A 的右子树是否包含树 B 的右子树,即调用 $\textit{dfs}(A.right, B.right)$。如果其中有一个函数返回 `false`,则树 B 不是树 A 的子结构,返回 `false`;否则,返回 `true`
6464

6565
在函数 `isSubStructure` 中,我们首先判断树 A 和树 B 是否为空,如果其中有一个为空,则树 B 不是树 A 的子结构,返回 `false`。然后,我们调用 $\textit{dfs}(A, B),ドル判断树 A 是否包含树 B。如果是,则返回 `true`;否则,递归判断树 A 的左子树是否包含树 B,以及树 A 的右子树是否包含树 B。如果其中有一个返回 `true`,则树 B 是树 A 的子结构,返回 `true`;否则,返回 `false`
6666

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /