Skip to content

Commit f8f3f64

Browse files
committed
🐱(tree): 572. 另一个树的子树
补充思路
1 parent 3cbb0da commit f8f3f64

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

docs/data-structure/tree/recursion/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,12 @@ func getMax(a int, b int) int {
10341034

10351035
[437](/tree/437.md) 递归思路类似。
10361036

1037+
`t` 是否为 `s` 的子树,存在三种情况:
1038+
1039+
- `t``s` 相同
1040+
- `t``s` 的左子树
1041+
- `t``s` 的右子树
1042+
10371043
```python
10381044
class Solution(object):
10391045
def isSubtree(self, s, t):
@@ -1047,6 +1053,9 @@ class Solution(object):
10471053
return self.isSubtreeWithRoot(s, t) or self.isSubtree(s.left, t) or self.isSubtree(s.right, t)
10481054

10491055
def isSubtreeWithRoot(self, s, t):
1056+
"""
1057+
t 与 s 是否相同
1058+
"""
10501059
if s is None and t is None:
10511060
return True
10521061
if s is None or t is None:

0 commit comments

Comments
 (0)