对称的二叉树
class Solution {
public:
bool dfs(TreeNode* l,TreeNode* r)
{
if(l==NULL&&r==NULL)
return true;
else if(l&&r)
return l->val==r->val&&dfs(l->left,r->right)&&dfs(l->right,r->left);
return false;
}
bool isSymmetric(TreeNode* root) {
if(!root) return true;
return dfs(root->left,root->right);
}
};
有帮助的话可以点个赞,我会很开心的~