My recursive solution in Py. Accepted. Feedback?


  • 0
    L
    def isSameTree(self, p, q):
            if p and q and p.val != q.val:
                return False
            if p == None and q == None:
                return True
            elif p == None or q == None:
                return False
            return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
    

    Your feedback is appreciated. I am wondering if there is a more elegant way of doing this.


Log in to reply
 

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