三个月算法进阶--day58
目录
两次递归
leetcode剑指offer第26题树的子结构
class Solution:
def isSubStructure(self, A: TreeNode, B: TreeNode) -> bool:
def helper(a, b):
if not b:
return True
if not a:
return False
if a.val != b.val:
return False
return helper(a.left, b.left) and helper(a.right, b.right)
return bool(A and B) and (helper(A, B) or self.isSubStructure(A.left, B) or self.isSubStructure(A.right, B))