You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
414 B
24 lines
414 B
2 years ago
|
package class10;
|
||
|
|
||
|
// 本题测试链接 : https://leetcode.com/problems/jump-game-ii/
|
||
|
public class Code01_JumpGame {
|
||
|
|
||
|
public static int jump(int[] arr) {
|
||
|
if (arr == null || arr.length == 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
int step = 0;
|
||
|
int cur = 0;
|
||
|
int next = 0;
|
||
|
for (int i = 0; i < arr.length; i++) {
|
||
|
if (cur < i) {
|
||
|
step++;
|
||
|
cur = next;
|
||
|
}
|
||
|
next = Math.max(next, i + arr[i]);
|
||
|
}
|
||
|
return step;
|
||
|
}
|
||
|
|
||
|
}
|