Initial commit
This commit is contained in:
11
53. Maximum Subarray/53. Maximum Subarray.csproj
Normal file
11
53. Maximum Subarray/53. Maximum Subarray.csproj
Normal file
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_53._Maximum_Subarray</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
10
53. Maximum Subarray/Program.cs
Normal file
10
53. Maximum Subarray/Program.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace _53._Maximum_Subarray
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello, World!");
|
||||
}
|
||||
}
|
||||
}
|
||||
16
53. Maximum Subarray/Solution.cs
Normal file
16
53. Maximum Subarray/Solution.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace _53._Maximum_Subarray;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int MaxSubArray(int[] nums)
|
||||
{
|
||||
int best_sum = int.MinValue;
|
||||
int current_sum = 0;
|
||||
foreach(var x in nums)
|
||||
{
|
||||
current_sum = Math.Max(x, current_sum + x);
|
||||
best_sum = Math.Max(best_sum, current_sum);
|
||||
}
|
||||
return best_sum;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user