My wrong answer got accepted


  • 1
    W
    class Solution {
    public:
        bool canJump(int A[], int n) {
            if(n == 0 || n == 1)
                return true;
            int* b = (int*)malloc(n*sizeof(int));
            int i;
            for(i = 0; i < n - 1; i++)      // A[n-1] is left out 
            {
                b[i] = A[i] + i;
            }
            bool found;
            int j;
            for(i = 0; i < A[0]; i++)
            {
                j = i;
                while(j < n - 1)
                {
                    if(j < b[j])
                        j = b[j];
                    else
                    {
                        found = false;
                        break;
                    }
                }
                if(j >= n -1)
                {
                    found = true;
                    break;
                }
            }
            return found;
        }
    };
    

    The 1 1 2 2 0 1 1 should return true.
    This code return false and got accepted.


  • 1
    S

    Thanks @wangshiyu1991 for pointing it out. Since discuss is English only, I edited the comments in your code.

    We have already added the test case you mentioned. This code should get wrong answer now. :)


Log in to reply
 

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