[Recusive solution for symmetric tree]: is it an optimal solution to use inorderTraversal?
The approach I have is:\n1. get two vectors which saves both left and right sides of the root in inorderTraversal format.\n2. compare the vectors to see if they
The approach I have is:\n1. get two vectors which saves both left and right sides of the root in inorderTraversal format.\n2. compare the vectors to see if they are symmetric.\nIt needs extra O(2n) space, not sure if this is an accepted solution. Or is there any better to solve this problem recursively.\n\n    /*recusive*/\n    class inorderTraversal {\n    public:\n        vector<int> solution(TreeNode *root) {\n            // IMPORTANT: Please reset any member data you declared, as\n            // the same Solution instance will be reused for each test case.\n            vector <int> results;\n    \t\tvector <int> rightResults;\n    \t\tif(!root) return results;\n    \t\tresults=solution(root->left);\n            results.insert(results.end(),root->val);\n    \t\trightResults=solution(root->right);\n    \t\tif(!rightResults.empty())\n    \t\t\tresults.insert(results.end(),rightResults.begin(), rightResults.end());\n        }\n    };\n    \n    class Solution {\n    public:\n        bool isSymmetric(TreeNode *root) {\n            // IMPORTANT: Please reset any member data you declared, as\n            // the same Solution instance will be reused for each test case.\n            if(!root) return true;\n    \t\tinorderTraversal instance;\n    \t\tvector <int> leftResults=instance.solution(root->left);\n    \t\tvector <int> rightResults=instance.solution(root->right);\n    \t\tif(leftResults.size()!=rightResults.size())\n    \t\t\treturn false;\n    \t\tint size=leftResults.size();\n    \t\tif(!size) return true;\n    \n    \t\tfor(int i=0; i< size; i++)\n    \t\t{\n    \t\t\tif(leftResults[i]!=rightResults[size-1-i])\n    \t\t\t\treturn false;\n    \t\t}\n    \t\treturn true;\n        }\n    };
[]