题解 | #对称的二叉树#
对称的二叉树
https://www.nowcoder.com/practice/ff05d44dfdb04e1d83bdbdab320efbcb
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};
*/
class Solution {
public:
bool isSymmetrical(TreeNode* pRoot) {
return a(pRoot,pRoot);
}
bool a(TreeNode *l,TreeNode *r){
if(l==nullptr&&r==nullptr) return true;
if(l==nullptr||r==nullptr||l->val!=r->val){
return false;
}
return a(r->left,l->right)&&a(r->right,l->left);
}
};
查看5道真题和解析

