share my easy understanding C++ solution


  • 0
    F
    class Solution {
    public:
        bool helper(TreeNode *root,TreeNode *mirror){
            if(root==NULL&&mirror==NULL) return true;
            else if(root!=NULL&&mirror!=NULL){
                if(root->val==mirror->val) {
                    bool a=helper(root->left,mirror->right);
                    bool b=helper(root->right,mirror->left);
                    return a&b;
                }
                else return false;
            }else{
                return false;
            }
        }
        bool isSymmetric(TreeNode* root) {
            return helper(root,root);
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.