mirror of
https://github.com/CyC2018/Interview-Notebook.git
synced 2026-10-30 07:33:45 +00:00
Update 26. 树的子结构.md
题目链接改为力扣中的对应题目,题目描述和代码按该题的接口调整。
This commit is contained in:
+4
-4
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user