mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
update 0045.跳跃游戏II.md 修改算法重复语义
This commit is contained in:
@ -76,11 +76,9 @@ public:
|
|||||||
for (int i = 0; i < nums.size(); i++) {
|
for (int i = 0; i < nums.size(); i++) {
|
||||||
nextDistance = max(nums[i] + i, nextDistance); // 更新下一步覆盖最远距离下标
|
nextDistance = max(nums[i] + i, nextDistance); // 更新下一步覆盖最远距离下标
|
||||||
if (i == curDistance) { // 遇到当前覆盖最远距离下标
|
if (i == curDistance) { // 遇到当前覆盖最远距离下标
|
||||||
if (curDistance < nums.size() - 1) { // 如果当前覆盖最远距离下标不是终点
|
ans++; // 需要走下一步
|
||||||
ans++; // 需要走下一步
|
curDistance = nextDistance; // 更新当前覆盖最远距离下标(相当于加油了)
|
||||||
curDistance = nextDistance; // 更新当前覆盖最远距离下标(相当于加油了)
|
if (nextDistance >= nums.size() - 1) break; // 当前覆盖最远距到达集合终点,不用做ans++操作了,直接结束
|
||||||
if (nextDistance >= nums.size() - 1) break; // 下一步的覆盖范围已经可以达到终点,结束循环
|
|
||||||
} else break; // 当前覆盖最远距到达集合终点,不用做ans++操作了,直接结束
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ans;
|
return ans;
|
||||||
|
Reference in New Issue
Block a user