My c++ solution


  • 0
    Z
    bool isSy(TreeNode* left, TreeNode* right)
    {
        if(left==NULL&&right!=NULL)
        {
            return false;
        }
        if(left!=NULL&&right==NULL)
        {
            return false;
        }
         if(left==NULL&&right==NULL)
        {
            return true;
        }
        if(left->val!=right->val)
        {
            return false;
        }
        return isSy(left->left, right->right)&&isSy(left->right,right->left);
    }
    bool isSymmetric(TreeNode* root) {
        if(root==NULL)
            return true;
        return isSy(root->left, root->right);
    }

Log in to reply
 

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