赞
踩
题目:
题解:
- int jump(int* nums, int numsSize) {
- int steps = 0;
- int maxReach = 0;
- int lastJump = 0;
-
- for (int i = 0; i < numsSize - 1; ++i) {
- maxReach = (i + nums[i] > maxReach) ? i + nums[i] : maxReach;
-
- if (i == lastJump) {
- lastJump = maxReach;
- ++steps;
-
- if (maxReach >= numsSize - 1) {
- return steps;
- }
- }
- }
-
- return 0;
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。