From a66e5e39ba70ab6d3fecaa29296d19245582ca00 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sat, 30 Dec 2023 10:16:43 +0800 Subject: [PATCH] =?UTF-8?q?Update.0045=E8=B7=B3=E8=B7=83=E6=B8=B8=E6=88=8F?= =?UTF-8?q?2=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E7=89=88=E6=9C=AC=E4=BA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0045.跳跃游戏II.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0045.跳跃游戏II.md b/problems/0045.跳跃游戏II.md index aab27b27..e006caa2 100644 --- a/problems/0045.跳跃游戏II.md +++ b/problems/0045.跳跃游戏II.md @@ -464,6 +464,27 @@ impl Solution { } } ``` +### C# +```csharp +// 版本二 +public class Solution +{ + public int Jump(int[] nums) + { + int cur = 0, next = 0, step = 0; + for (int i = 0; i < nums.Length - 1; i++) + { + next = Math.Max(next, i + nums[i]); + if (i == cur) + { + cur = next; + step++; + } + } + return step; + } +} +```