Jump Game LeetCode solution in Java

1
class Solution {
2
public boolean canJump(int[] nums) {
3
int maxjump = 0;
4
for (int i = 0; i < nums.length; i++) {
5
// If the current index 'i' is less than current maximum jump 'curr'. It means there is no way
6
// to jump to current index...
7
// so we should return false
8
if (maxjump < i) return false;
9
else maxjump = Math.max(maxjump, nums[i] + i); // Update the current maximum jump...
10
}
11
return true;
12
}
13
}
14

15
// nums[i]+1 gives themax jump index possible from i

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0