c语言版
bool compare(struct TreeNode* p1, struct TreeNode* p2){
if(p1 == NULL && p2 == NULL){
return true;
}else if(p1 != NULL && p2 == NULL){
return false;
}else if(p2 != NULL && p1 == NULL){
return false;
}else {
if(p1->val != p2->val) {
return false;
}else {
return compare(p1->left, p2->right) && compare(p2->left, p1->right);
}
}
}
bool isSymmetric(struct TreeNode* root){
if(root == NULL) {
return true;
}
if(root->left == NULL && root->right != NULL){
return false;
}else if (root->right == NULL && root->left != NULL){
return false;
}else {
return compare(root->left, root->right);
}
}