19 求两棵树是否相同

优质
小牛编辑
132浏览
2023-12-01
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