12345678910111213 |
- from typing import Optional
- from tree import TreeNode
- class Solution:
- def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
- if not p and not q:
- return True
- elif not p or not q:
- return False
- elif p.val != q.val:
- return False
- else:
- return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
|