Update0053.最大子序和,添加C#贪心

This commit is contained in:
eeee0717
2023-12-27 09:49:34 +08:00
parent 7924803206
commit a937b76746

View File

@ -406,6 +406,26 @@ object Solution {
} }
} }
``` ```
### C#
**贪心**
```csharp
public class Solution
{
public int MaxSubArray(int[] nums)
{
int res = Int32.MinValue;
int count = 0;
for (int i = 0; i < nums.Length; i++)
{
count += nums[i];
res = Math.Max(res, count);
if (count < 0) count = 0;
}
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">