3ms C++ easy understand


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

Log in to reply
 

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