Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e73aec0

Browse files
ADD Min-Cost-Climbing-Stairs problem #57
1 parent afb3cdb commit e73aec0

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Easy/min-cost-climbing-stairs.cs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
public class Solution
4+
{
5+
public static int MinCostClimbingStairs(int[] cost)
6+
{
7+
if (cost == null || cost.Length < 2)
8+
{
9+
return 0;
10+
}
11+
12+
for (int i = cost.Length - 3; i >= 0; i--)
13+
{
14+
cost[i] += Math.Min(cost[i + 1], cost[i + 2]);
15+
}
16+
17+
return Math.Min(cost[0], cost[1]); // Because I can either start from the step with index 0 or 1.
18+
}
19+
20+
public static void Main(string[] args)
21+
{
22+
int[] cost = { 10, 50 };
23+
24+
Console.WriteLine(MinCostClimbingStairs(cost));
25+
26+
Console.ReadKey();
27+
}
28+
}
29+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /