Day i do not know
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>_746._Min_Cost_Climbing_Stairs</RootNamespace>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
9
746. Min Cost Climbing Stairs/Program.cs
Normal file
9
746. Min Cost Climbing Stairs/Program.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace _746._Min_Cost_Climbing_Stairs;
|
||||
|
||||
internal class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine(new Solution().MinCostClimbingStairs(new int[] { 1, 100, 1, 1, 1, 100, 1, 1, 100, 1 }));
|
||||
}
|
||||
}
|
||||
17
746. Min Cost Climbing Stairs/Solution.cs
Normal file
17
746. Min Cost Climbing Stairs/Solution.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace _746._Min_Cost_Climbing_Stairs;
|
||||
|
||||
public class Solution
|
||||
{
|
||||
public int MinCostClimbingStairs(int[] cost)
|
||||
{
|
||||
int prev = cost[0];
|
||||
int cur = cost[1];
|
||||
for(int i = 2; i < cost.Length; i++)
|
||||
{
|
||||
int next = cost[i] + Math.Min(prev, cur);
|
||||
prev = cur;
|
||||
cur = next;
|
||||
}
|
||||
return Math.Min(prev, cur);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user