Loading

LeetCode problem#55

Jump Game

Solved in 1 languageJava

Solve it on LeetCode(opens in a new tab)

Solution

20 lines
1class Solution {
2  public boolean canJump(int[] nums) {
3      int jumps = 0;
4
5      for (int i = 0; i < nums.length; i++)
6      {
7          if (jumps < 0)
8          {
9              return false;
10          }
11          else if (nums[i] > jumps)
12          {
13              jumps = nums[i];
14          }
15          jumps--;
16      }
17
18      return true;
19  }
20}

Want a walkthrough of this Java solution?

Get a step-by-step explanation of the idea behind the code.

All problems

Problem statements belong to LeetCode and are on leetcode.com. We're not affiliated with LeetCode.