class Solution:
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
if p is None and q is None:
return True
if p is None:
return False
if q is None:
return False
if p.val != q.val:
return False
else:
left = self.isSameTree(p.left, q.left)
right = self.isSameTree(p.right, q.right)
return left and right
网友评论