-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkipGame.java
More file actions
42 lines (37 loc) · 969 Bytes
/
SkipGame.java
File metadata and controls
42 lines (37 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package algorithm.array;
import java.util.Arrays;
public class SkipGame {
public static void main(String[] args) {
int res = jump(new int[]{2,1,1,1,1});
System.out.println(res);
}
public static int jump(int[] nums) {
int cnt = 0;
if (nums.length == 1) {
return cnt;
}
for (int i = 0; i < nums.length;) {
int s = nums[i];
cnt++;
if (i+s >= nums.length-1) {
return cnt;
}
int m = nums[i];
int j = 1;
int k = i;
for (; j <= s; j++) {
if (m <= nums[i+j]+j) {
m = nums[i+j] +j;
k = i+j;
}
// m = Math.max(m, nums[i+j] + j);
}
i = k;
}
String x = new String("xxx");
x.toCharArray();
// x.
// StringBuilder
return cnt++;
}
}