Bootstrap

C语言 | Leetcode C语言题解之第45题跳跃游戏II

题目:

题解:

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;
}
;