[leetcode] Jump Game 1

Jump Game

Given an array of non-negative integers, you are initially positioned at the first index of the array.

Each element in the array represents your maximum jump length at that position.

Determine if you are able to reach the last index.

For example:
A = [2,3,1,1,4], return true.

A = [3,2,1,0,4], return false.




class Solution {
    bool canJump(int A[], int n) {
        int right = 0;
        for(int i = 0; i <= right; i++){
            right = right > i + A[i]? right: i + A[i];
            if(right >= n - 1) return true;
        return false;





Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

One thought on “[leetcode] Jump Game