leetcode-面试题26-数的子结构

题目描述:

 

 方法一:O(MN) O(M)

class Solution:
    def isSubStructure(self, A: TreeNode, B: TreeNode) -> bool:
        def equal(A,B):
            if not B:return True
            if not A or A.val != B.val:return False
            return equal(A.left,B.left) and equal(A.right,B.right)
        
        return bool(A and B) and (equal(A,B) or self.isSubStructure(A.left,B) or self.isSubStructure(A.right,B))

 

posted @ 2020-04-17 15:11  oldby  阅读(91)  评论(0编辑  收藏  举报