美文网首页
44.求两棵树是否相同

44.求两棵树是否相同

作者: vbuer | 来源:发表于2018-09-04 09:59 被阅读21次
def isSameTree(p, q):
    if p == None and q == None:
        return True
    elif p and q :
        return p.val == q.val and isSameTree(p.left,q.left) and isSameTree(p.right,q.right)
    else :
        return False

相关文章

网友评论

      本文标题:44.求两棵树是否相同

      本文链接:https://www.haomeiwen.com/subject/uezniftx.html