Skip to content

Instantly share code, notes, and snippets.

@sheldonrobinson
Created October 6, 2019 00:14
Show Gist options
  • Save sheldonrobinson/2999bfcccde98ad5e4ed02a6060645b2 to your computer and use it in GitHub Desktop.
Save sheldonrobinson/2999bfcccde98ad5e4ed02a6060645b2 to your computer and use it in GitHub Desktop.
CodeSignal Solution isTreeSymmetric
#
# Binary trees are already defined with this interface:
# class Tree(object):
# def __init__(self, x):
# self.value = x
# self.left = None
# self.right = None
def isEqual(left, right):
if left == None and right == None:
return True
if right == None and left != None:
return False
if left == None and right != None:
return False
if left.value != right.value:
return False
return isEqual(left.right, right.left) and isEqual(left.left, right.right)
def isTreeSymmetric(t):
if t == None:
return True
return isEqual(t.left, t.right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment