AcWing 39. 对称的二叉树
原题链接
简单
作者:
owonder
,
2020-08-13 10:52:01
,
所有人可见
,
阅读 390
C++ 代码
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode* root) {
if(!root){
return true;
}
return isSymmetric(root->left,root->right);
}
bool isSymmetric(TreeNode* left,TreeNode* right){
if(!left||!right){
return !left&&!right;
}
return (left->val==right->val)&&isSymmetric(left->left, right->right)&&isSymmetric(left->right, right->left);
}
};