symmetric_tree.py 336 B

12345678910111213141516
  1. from typing import Optional
  2. from tree import TreeNode
  3. class Polution:
  4. def isSymmetric(self, root: Optional[TreeNode]) -> bool:
  5. p = root.left
  6. q = root.right
  7. while p and q:
  8. if p.val == q.val:
  9. p = p.left
  10. q = q.right
  11. else:
  12. return False