Python iterative way using a queue
Each iteration, it checks whether two nodes are symmetric and then push (node1.left, node2.right), (node1.right, node2.left) to the end of queue.\n\n    class S
Each iteration, it checks whether two nodes are symmetric and then push (node1.left, node2.right), (node1.right, node2.left) to the end of queue.\n\n    class Solution:\n    # @param root, a tree node\n    # @return a boolean\n    def isSymmetric(self, root):\n        if not root:\n            return True\n\n        dq = collections.deque([(root.left,root.right),])\n        while dq:\n            node1, node2 = dq.popleft()\n            if not node1 and not node2:\n                continue\n            if not node1 or not node2:\n                return False\n            if node1.val != node2.val:\n                return False\n            # node1.left and node2.right are symmetric nodes in structure\n            # node1.right and node2.left are symmetric nodes in structure\n            dq.append((node1.left,node2.right))\n            dq.append((node1.right,node2.left))\n        return True
['Python']