```
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(!root)return true;
return g(root->left,root->right);
}
bool g(TreeNode*n,TreeNode*p){
if(!n&&!p) return true;
if(!n||!p) return false;
return n->val == p->val && g(n->left,p->right) && g(n->right,p->left);
}
};
```