Update0053.最大子序和,添加C#贪心
This commit is contained in:
parent
7924803206
commit
a937b76746
|
|
@ -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">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
|
|
|
|||
Loading…
Reference in New Issue