思路:递归
/**
* 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==NULL) return true;
return check(root->left,root->right);
}
bool check(TreeNode* l,TreeNode* r){
if(l==NULL&&r==NULL) return true;
if(l==NULL||r==NULL) return false;
if(l->val!=r->val) return false;
return check(l->right,r->left)&&check(l->left,r->right);
}
};