a guest Jul 24th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand