We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 508fb57 commit d79ec0fCopy full SHA for d79ec0f
Greedy/55_Jump_Game.java
@@ -1,18 +1,11 @@
1
class Solution {
2
public boolean canJump(int[] nums) {
3
- if (nums == null || nums.length == 0) {
4
- return false;
5
- }
6
-
7
- int reachable = 0;
+ int furthestSoFar = 0, goal = nums.length - 1;
8
9
- for (int i = 0; i < nums.length; i++) {
10
- if (reachable < i) {
11
12
13
- reachable = Math.max(reachable, i + nums[i]);
+ for (int i = 0; i <= furthestSoFar && furthestSoFar < goal; i++) {
+ furthestSoFar = Math.max(furthestSoFar, nums[i] + i);
14
}
15
16
- return true;
+ return furthestSoFar >= goal;
17
18
0 commit comments