1 /** 2 * Definition for a binary tree node. 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 isSymmetric(TreeNode* root) { 13 return ismirror(root,root); 14 } 15 bool ismirror(TreeNode* t1,TreeNode* t2){ 16 if(t1==NULL && t2==NULL) return true;//最基本单元情况两个指针都是空 17 if(t1==NULL || t2==NULL) return false;//只有一个空,那就返回false,不镜像了 18 if(t1->val != t2->val) return false; 19 return ismirror(t1->left,t2->right)&&ismirror(t1->right,t2->left); 20 } 21 };