Incorrect test case output

  • 0

    I do not see the error in my solution, anyone can tell me what is wrong? thanks

        bool canCross(vector<int>& stones) {
            if(stones[1]!=1) return false;
            for(int i=1, last=stones.size()-1; i<last; i++){ // for each jump starting from second stone to the before last stone
                int prev=stones[i]-stones[i-1]; //previous jump length
                int next=stones[i+1]-stones[i]; //next jump length
                if(next<prev-1 || prev+1<next) return false; // if cannot go to next stone
            return true; // otherwise frog crosses river
    Input:      [0,1,3,5,6,8,12,17]
    Output:     false               //frog can't jump from 6th to 7th stone
    Expected:   true

Log in to reply

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