1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| class Solution { public int jump(int[] nums) { int ans = 0, n = nums.length, right = 0, newRight = 0; for (int i = 0; i < n; ++i) { if (right >= n - 1) { break; } newRight = Math.max(newRight, i + nums[i]); if (i == right) { right = newRight; ans++; } } return ans; } }
|