/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} * }; */ class Solution { public: bool isSymmetric(TreeNode* root) { if(root==NULL) return true; return helper(root->left,root->right); } bool helper(TreeNode* L, TreeNode* R){ if(L==NULL&&R==NULL) return true; else if(L&&R){ if(L->val==R->val) return helper(L->left,R->right)&&helper(L->right,R->left); else return false; }else return false; } };