DEV Community

Debesh P.
Debesh P.

Posted on

55. Jump Game | LeetCode | Top Interview 150 | Coding Questions

Problem Link

https://leetcode.com/problems/jump-game/


leetcode 55


Solution

class Solution {
    public boolean canJump(int[] nums) {
        int n = nums.length;
        int goal = n - 1;
        for(int i = n - 2; i >= 0; i--) {
            if(i + nums[i] >= goal) {
                goal = i;
            }
        }

        return goal == 0;
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)