class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(!root) return true;
return fun(root->left, root->right);
}
bool fun(TreeNode *root1, TreeNode *root2){
if(!root1 && !root2) return true; // 同时为空 true
if((!root1&&root2) || (root1&&!root2)) return false; // 其中一个为空 false
return fun(root1->left, root2->right) && fun(root1->right, root2->left) && root1->val == root2->val;
}
};
京公网安备 11010502036488号