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; + } +} +```
diff --git a/problems/0055.跳跃游戏.md b/problems/0055.跳跃游戏.md
index bedb09ab..086fd64f 100644
--- a/problems/0055.跳跃游戏.md
+++ b/problems/0055.跳跃游戏.md
@@ -258,6 +258,23 @@ object Solution {
}
}
```
+### C#
+```csharp
+public class Solution
+{
+ public bool CanJump(int[] nums)
+ {
+ int cover = 0;
+ if (nums.Length == 1) return true;
+ for (int i = 0; i <= cover; i++)
+ {
+ cover = Math.Max(i + nums[i], cover);
+ if (cover >= nums.Length - 1) return true;
+ }
+ return false;
+ }
+}
+```
diff --git a/problems/0122.买卖股票的最佳时机II.md b/problems/0122.买卖股票的最佳时机II.md
index 2c2ab225..69706e36 100644
--- a/problems/0122.买卖股票的最佳时机II.md
+++ b/problems/0122.买卖股票的最佳时机II.md
@@ -406,6 +406,21 @@ object Solution {
}
}
```
+### C#
+```csharp
+public class Solution
+{
+ public int MaxProfit(int[] prices)
+ {
+ int res = 0;
+ for (int i = 0; i < prices.Length - 1; i++)
+ {
+ res += Math.Max(0, prices[i + 1] - prices[i]);
+ }
+ return res;
+ }
+}
+```