Advertisement
Guest User

Untitled

a guest
Jul 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. # Definition for a binary tree node.
  2. # class TreeNode:
  3. # def __init__(self, x):
  4. # self.val = x
  5. # self.left = None
  6. # self.right = None
  7.  
  8. class Solution:
  9. def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
  10. if not p and not q: return True
  11. if not p or not q: return False
  12. return p.val == q.val and self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement