# Definition for a binary tree node.
class TreeNode(object):
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution(object):
    # Op1 recursion
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        return self.isMirror(root, root)

    def isMirror(self, root1, root2):
        if root1 is None and root2 is None:
            return True
        if root1 and root2 and root1.val == root2.val:
            return self.isMirror(root1.left, root2.right) and \
                self.isMirror(root1.right, root2.left)
        return False

    # Op2 Non-recursion
    def isSymmetric2(self, root):
        if root is None: return True
        stack1, stack2 = [], []
        stack1.append(root.left)
        stack2.append(root.right)
        while stack1 and stack2:
            node1, node2 = stack1.pop(), stack2.pop()
            if node1 is None and node2 is None: continue
            if node1 is None or node2 is None: return False
            if node1.val != node2.val: return False
            stack1.append(node1.left)
            stack1.append(node1.right)
            stack2.append(node2.right)
            stack2.append(node2.left)
        return True
        

mytree = TreeNode(1)
mytree.left = TreeNode(2)
mytree.right = TreeNode(3)
print(mytree.left == mytree.right)
test = Solution()
print(test.isSymmetric(mytree))
