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.

public class Solution {
    /**
     * @param A: A list of integers
     * @return: The boolean answer
     */
    public boolean canJump(int[] A) {
        // wirte your code here
        if (A == null || A.length == 0) return false;

        int n = A.length;
        boolean[] dp = new boolean[n];
        dp[0] = true;
        for (int i = 0; i < n; i ++) {
            for (int j = i - 1; j >=0; j--) {
                if (dp[j] && A[j] >= i - j) {
                    dp[i] = true;
                    break;
                }//at most A[i] step, we can jump less
            }
        }
        return dp[n-1];
    }
    //greedy algorithm
    public boolean canJump(int[] A) {
        // wirte your code here
        if (A == null || A.length == 0) return false;
        int index = A.length - 1;
        for (int i = A.length - 1; i >= 0; i--) {
            if (A[i] >= index - i) {
                index = i;
            }
            //to get over the last index, there must be an i that A[i] + i >= index
        }
        return index == 0;
    }
}
class Solution:
    def canJump(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """

        if not nums or len(nums) == 1:
            return True

        rightmost = end = 0
        for i, num in enumerate(nums[:-1]):
            rightmost = max(rightmost, i + num)
            if i == end:
                end = rightmost
                if end >= len(nums) - 1:
                    return True
        return False