Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #
  2. # Binary trees are already defined with this interface:
  3. # class Tree(object):
  4. # def __init__(self, x):
  5. # self.value = x
  6. # self.left = None
  7. # self.right = None
  8.  
  9. def isEqual(left, right):
  10. if left == None and right == None:
  11. return True
  12. if right == None and left != None:
  13. return False
  14. if left == None and right != None:
  15. return False
  16. if left.value != right.value:
  17. return False
  18.  
  19. return isEqual(left.right, right.left) and isEqual(left.left, right.right)
  20.  
  21. def isTreeSymmetric(t):
  22. if t == None:
  23. return True
  24. return isEqual(t.left, t.right)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement