URL: https://leetcode.com/problems/jump-game/ Signed-off-by: Matej Focko <me@mfocko.xyz>
15 lines
332 B
Java
15 lines
332 B
Java
class Solution {
|
|
public boolean canJump(int[] nums) {
|
|
var last = 0;
|
|
for (var i = 0; i < nums.length && last < nums.length - 1; ++i) {
|
|
if (i > last) {
|
|
// can't reach the current position
|
|
return false;
|
|
}
|
|
|
|
last = Math.max(last, i + nums[i]);
|
|
}
|
|
|
|
return last >= nums.length - 1;
|
|
}
|
|
}
|