DEV Community

Debesh P.
Debesh P.

Posted on • Edited on

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

Problem Link

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


Detailed Step-by-Step Explanation

https://leetcode.com/problems/jump-game/solutions/7416662/best-java-solution-beats-200-simplest-ap-t6xp


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)