Skip to content

Commit ee6b16b

Browse files
committed
3
1 parent 1958e6d commit ee6b16b

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

JumpGameII/JumpGameII.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int jump(int A[], int n) {
4+
// Start typing your C/C++ solution below
5+
// DO NOT write int main() function
6+
7+
int begin = 0, end = 0;
8+
int min_step = 0;
9+
int max_next = 0;
10+
11+
while (end < n - 1) {
12+
min_step += 1;
13+
for (int i = begin; i <= end; i++)
14+
max_next = max(max_next, i + A[i]);
15+
if (max_next <= end)
16+
return -1;
17+
begin = end + 1;
18+
end = max_next;
19+
}
20+
return min_step;
21+
}
22+
};

0 commit comments

Comments
 (0)