SHARE
TWEET

Untitled

a guest Oct 24th, 2019 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top