class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(!root) return true;
bool isMatch1(TreeNode* p,TreeNode* q);
return isMatch1(root->left,root->right);
}
};
bool isMatch1(TreeNode* p,TreeNode* q)
{
if(!p&!q) return true;
if(p&&!q||!p&&q) return false;
if(p&&q&&p->val==q->val) return isMatch1(p->left,q->right)&&isMatch1(p->right,q->left);
return false;
}
对称二叉树(递归)
最新推荐文章于 2024-10-04 10:00:00 发布