From e1abedc13ad4d5f744ecc27fa9931aa24508364b Mon Sep 17 00:00:00 2001 From: Guanzhong Pan Date: Wed, 13 Apr 2022 09:41:50 +0100 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=200055.=E8=B7=B3=E8=B7=83?= =?UTF-8?q?=E6=B8=B8=E6=88=8F.md=20C=E8=AF=AD=E8=A8=80=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0055.跳跃游戏.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md index c0890f75..4ba0c03b 100644 --- a/problems/0055.跳跃游戏.md +++ b/problems/0055.跳跃游戏.md @@ -154,6 +154,28 @@ var canJump = function(nums) { }; ``` +### C +```c +#define max(a, b) (((a) > (b)) ? (a) : (b)) + +bool canJump(int* nums, int numsSize){ + int cover = 0; + + int i; + // 只可能获取cover范围中的步数,所以i<=cover + for(i = 0; i <= cover; ++i) { + // 更新cover为从i出发能到达的最大值/cover的值中较大值 + cover = max(i + nums[i], cover); + + // 若更新后cover可以到达最后的元素,返回true + if(cover >= numsSize - 1) + return true; + } + + return false; +} +``` + -----------------------