diff --git a/problems/0045.跳跃游戏II.md b/problems/0045.跳跃游戏II.md index d290f55e..c6433ea8 100644 --- a/problems/0045.跳跃游戏II.md +++ b/problems/0045.跳跃游戏II.md @@ -492,7 +492,34 @@ impl Solution { } } ``` +### C + +```c +#define max(a, b) ((a) > (b) ? (a) : (b)) + +int jump(int* nums, int numsSize) { + if(numsSize == 1){ + return 0; + } + int count = 0; + // 记录当前能走的最远距离 + int curDistance = 0; + // 记录下一步能走的最远距离 + int nextDistance = 0; + for(int i = 0; i < numsSize; i++){ + nextDistance = max(i + nums[i], nextDistance); + // 下标到了当前的最大距离 + if(i == nextDistance){ + count++; + curDistance = nextDistance; + } + } + return count; +} +``` + ### C# + ```csharp // 版本二 public class Solution @@ -518,3 +545,4 @@ public class Solution +