class Solution(object):
def isSymmetric(self, root):
self.tag_node = True
if root.left == None and root.right == None:
return True
elif root.left == None or root.right == None:
return False
else:
return self.compareTreeNode(root.left, root.right)
def compareTreeNode(self, tree1, tree2):
if (tree1 != None and tree2 == None) or (tree1 == None and tree2 != None) or (tree1.val != tree2.val):
self.tag_node = False
if tree1.left != None and tree2.right != None:
self.compareTreeNode(tree1.left, tree2.right)
elif tree1.left != None or tree2.right != None :
self.tag_node = False
if tree1.right != None and tree2.left != None:
self.compareTreeNode(tree1.right, tree2.left)
elif tree1.right != None or tree2.left != None:
self.tag_node = False
return self.tag_node