mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update0053.最大子序和,添加C#贪心
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user