Python 5 line solution


  • 1

    class Solution(object):
    def isSameTree(self, p, q):
    if(p==None and q!=None):return False
    elif (p!=None and q==None):return False
    elif p==None and q==None:return True
    else:
    if(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.