1 /** 2 * Definition for binary tree 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution { 11 public: 12 bool isS(TreeNode *t1, TreeNode *t2) { 13 if (!t1 && !t2) return true; 14 if (!t1 || !t2) return false; 15 if (t1->val != t2->val) return false; 16 return isS(t1->left, t2->right) && isS(t1->right, t2->left); 17 } 18 bool isSymmetric(TreeNode *root) { 19 if (!root) return true; 20 return isS(root->left, root->right); 21 } 22 };