Easy to read solution


  • 0
    C
    class Solution(object):
        def isSubtree(self, s, t):
            if s == None and t == None:
                return True
            if s == None:
                return False
            if s.val == t.val:
                if self.isSubTreeMatch(s,t):
                    return True
            return self.isSubtree(s.left,t) or self.isSubtree(s.right,t)
        def isSubTreeMatch(self, s, t):
            if s == None and t != None:
                return False
            if s != None and t == None:
                return False
            if s == None and t == None:
                return True
            if s.val != t.val:
                return False
            return self.isSubTreeMatch(s.left,t.left) and self.isSubTreeMatch(s.right,t.right)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.