/**
* Definition for binary tree
* 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 isSymmetric1(root->left,root->right);
}
bool isSymmetric1(TreeNode *p,TreeNode *q)
{
if(!p&&!q)
return true;
if(!p||!q)
return false;
return p->val==q->val && isSymmetric1(p->left,q->right) && isSymmetric1(p->right,q->left);
}
};
Symmetric Tree
最新推荐文章于 2022-04-21 23:25:34 发布