mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-13 22:35:09 +08:00
Update.买卖股票的最佳时机2,添加C#
This commit is contained in:
@ -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">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user