3 lines s1mple python solution


  • 1
    A
    def isSameTree(self, p, q):
        """
        :type p: TreeNode
        :type q: TreeNode
        :rtype: bool
        """
        if p == q == None: return True
        elif not (p and q and p.val == q.val): return False
        else: return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right)

Log in to reply
 

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