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.

28 lines
425 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package class008;
public class Code01_JumpGameII {
/*
* 评测代码可以直接去leetcode搜索Jump Game II
*
*/
public static int jump(int[] arr) {
if (arr == null || arr.length == 0) {
return 0;
}
int jump = 0;
int cur = 0;
int next = 0;
for (int i = 0; i < arr.length; i++) {
if (cur < i) {
jump++;
cur = next;
}
next = Math.max(next, i + arr[i]);
}
return jump;
}
}