1、题目
https://leetcode-cn.com/problems/symmetric-tree/submissions/
2、题意
题解1:递归
1:判断第一颗子树的左子树和第二颗子树的右子树是否相等;
2:判断第一颗子树的右子树和第二颗子树的左子数是否相等;
/**
* 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 check(root->left,root->right);
}
bool check(TreeNode* p,TreeNode* q)
{
if(!p&&!q) return true;
if(!p||!q||p->val!=q->val) return false;
return check(p->left,q->right)&&check(p->right,q->left);
}
};