From a937b7674623ecbbe24e61d20d6af7d771ab6304 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 27 Dec 2023 09:49:34 +0800 Subject: [PATCH] =?UTF-8?q?Update0053.=E6=9C=80=E5=A4=A7=E5=AD=90=E5=BA=8F?= =?UTF-8?q?=E5=92=8C=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E8=B4=AA=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0053.最大子序和.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/problems/0053.最大子序和.md b/problems/0053.最大子序和.md index 639c54bc..78c8b382 100644 --- a/problems/0053.最大子序和.md +++ b/problems/0053.最大子序和.md @@ -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; + } +} +``` +