From 7e80792a63f6d0b63745f2bb5c401b1a749afc1a Mon Sep 17 00:00:00 2001 From: YuZou Date: Fri, 31 Mar 2023 22:20:36 +0800 Subject: [PATCH] =?UTF-8?q?update=200045.=E8=B7=B3=E8=B7=83=E6=B8=B8?= =?UTF-8?q?=E6=88=8FII.md=20=E4=BF=AE=E6=94=B9=E7=AE=97=E6=B3=95=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E8=AF=AD=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0045.跳跃游戏II.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/problems/0045.跳跃游戏II.md b/problems/0045.跳跃游戏II.md index c6e4e9b5..2f6e8b67 100644 --- a/problems/0045.跳跃游戏II.md +++ b/problems/0045.跳跃游戏II.md @@ -76,11 +76,9 @@ public: for (int i = 0; i < nums.size(); i++) { nextDistance = max(nums[i] + i, nextDistance); // 更新下一步覆盖最远距离下标 if (i == curDistance) { // 遇到当前覆盖最远距离下标 - if (curDistance < nums.size() - 1) { // 如果当前覆盖最远距离下标不是终点 - ans++; // 需要走下一步 - curDistance = nextDistance; // 更新当前覆盖最远距离下标(相当于加油了) - if (nextDistance >= nums.size() - 1) break; // 下一步的覆盖范围已经可以达到终点,结束循环 - } else break; // 当前覆盖最远距到达集合终点,不用做ans++操作了,直接结束 + ans++; // 需要走下一步 + curDistance = nextDistance; // 更新当前覆盖最远距离下标(相当于加油了) + if (nextDistance >= nums.size() - 1) break; // 当前覆盖最远距到达集合终点,不用做ans++操作了,直接结束 } } return ans;