c++ solution recursive and iterative
Note\nThe answer is true when root is nullptr.\n\nclass Solution\n{\npublic:\n\t// recursive : 12 ms 16.7 MB\n\tbool isSymmetric(TreeNode* root) {\n\t\treturn !
**Note**\nThe answer is true when root is nullptr.\n```\nclass Solution\n{\npublic:\n\t// recursive : 12 ms 16.7 MB\n\tbool isSymmetric(TreeNode* root) {\n\t\treturn !root || isEquivalent(root->left, root->right);\n\t}\n\n\tbool isEquivalent(TreeNode* leftNode, TreeNode* rightNode)\n\t{\n\t\tif (!leftNode && rightNode || leftNode && !rightNode) return false;\n\n\t\treturn !leftNode || leftNode->val == rightNode->val && isEquivalent(leftNode->left, rightNode->right) && isEquivalent(leftNode->right, rightNode->left);\n\t}\n\n\t// iterative : 4 ms\t16.9 MB\n\tbool isSymmetric3(TreeNode* root) {\n\t\tif (!root) return true;\n\t\tqueue<TreeNode*> pending({ root->left, root->right });\n\n\t\twhile (!pending.empty())\n\t\t{\n\t\t\tTreeNode* l = pending.front();\n\t\t\tpending.pop();\n\t\t\tTreeNode* r = pending.front();\n\t\t\tpending.pop();\n\n\t\t\tif (!l && r || l && !r) return false;\n\t\t\tif (l)\n\t\t\t{\n\t\t\t\tif (l->val != r->val) return false;\n\t\t\t\tpending.push(l->left);\n\t\t\t\tpending.push(r->right);\n\t\t\t\tpending.push(l->right);\n\t\t\t\tpending.push(r->left);\n\t\t\t}\n\t\t}\n\n\t\treturn true;\n\t}\n};\n```
['Recursion', 'C', 'Iterator']