class Solution {
public:
    vector<int> left;
    vector<int> right;
    bool isSymmetrical(TreeNode* pRoot) {
        //空树对称
        if(pRoot==NULL){return true;}
        //只有一个节点对称
        if(pRoot->left==NULL&&pRoot->right==NULL)return true;
        //左右有一边为空
        if(pRoot->left==NULL||pRoot->right==NULL)return false;
        //通过左根右中序和右根左中序还存在缺陷,即假设根不相同,即23和23可能根分别为2,3
        if(pRoot->left->val!=pRoot->right->val)return false;
        inOreder(pRoot->left);
        inOrederMirror(pRoot->right);
        //大小不相同直接返回
        if(left.size()!=right.size()){
            return false;
        }
        for(int i=0;i<left.size();i++){
            if(left[i]!=right[i]){
                return false;
            }
        }
        return true;
    }
    void inOreder(TreeNode* pRoot){
        if(pRoot==NULL){
            return;
        }
        //中序遍历左右根
        inOreder(pRoot->left);
        left.push_back(pRoot->val);
        inOreder(pRoot->right);
    }
    void inOrederMirror(TreeNode* pRoot){
        if(pRoot==NULL){
            return;
        }
        //镜像中序遍历右左根
        inOrederMirror(pRoot->right);
        right.push_back(pRoot->val);
        inOrederMirror(pRoot->left);
    }
};