Skip to content

Commit b81ad7a

Browse files
author
lightmen
committed
add jump-game-ii.c
1 parent 6cbaec3 commit b81ad7a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

jump-game-ii.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
int jump(int* nums, int numsSize) {
2+
int i,cur_pos,max_pos;
3+
int ret;
4+
5+
ret = 0;
6+
cur_pos = 0;
7+
max_pos = 0;
8+
9+
for(i = 0; i < numsSize; ++i){
10+
if(cur_pos < i){
11+
ret++;
12+
cur_pos = max_pos;
13+
}
14+
max_pos = nums[i]+i > max_pos ? nums[i]+i : max_pos;
15+
}
16+
17+
return ret;
18+
}

0 commit comments

Comments
 (0)