/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(root==NULL)
return true;
vector<TreeNode *> left;
vector<TreeNode *> right;
vector<TreeNode *> templ;
vector<TreeNode *> tempr;
templ.push_back(root);
tempr.push_back(root);
while(!templ.empty()&&!tempr.empty())
{
vector<TreeNode*> prel;
vector<TreeNode*> prer;
int size = tempr.size();
for(int i = 0;i < size;i++)
{
if(templ[i]->left != NULL)
{
if(tempr[i]->right == NULL)
return false;
else if(tempr[i]->right->val == templ[i]->left->val)
{
prer.push_back(tempr[i]->right);
prel.push_back(templ[i]->left);
}
else
{
return false;
}
}
if(templ[i]->right != NULL)
{
if(tempr[i]->left == NULL)
return false;
else if(templ[i]->right->val == tempr[i]->left->val)
{
prer.push_back(tempr[i]->left);
prel.push_back(templ[i]->right);
}
else
{
return false;
}
}
}
templ = prel;
tempr = prer;
}
return true;
}
};