100. Same Tree
ιε½ιͺθ― val ηΈηοΌε€ηδΈ leave node ηζ ε΅γ
class Solution:
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
if not p and not q:
return True
if p and q and p.val != q.val:
return False
if p and q and p.val == q.val:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
Last updated
Was this helpful?