Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def isSameTree(self, p: Optional[TreeNode], q: Optional[TreeNode]) -> bool:
- # base case: if both are null nodes
- if not p and not q:
- return True
- # if both happen to be actual nodes
- if p and q:
- return (p.val == q.val) and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
- # if either of them is not a null node
- return False
Advertisement
Add Comment
Please, Sign In to add comment