Update.买卖股票的最佳时机2,添加C#

This commit is contained in:
eeee0717
2023-12-28 10:03:01 +08:00
parent a937b76746
commit 6eadd3eafc

View File

@ -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;
}
}
```
<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">