diff --git a/cs/min-cost-climbing-stairs.cs b/cs/min-cost-climbing-stairs.cs new file mode 100644 index 0000000..b7df12c --- /dev/null +++ b/cs/min-cost-climbing-stairs.cs @@ -0,0 +1,17 @@ +public class Solution { + public int MinCostClimbingStairs(int[] cost) { + int Get(int k) { + if (k < 0 || k >= cost.Length) { + return 0; + } + + return cost[k]; + } + + for (var i = cost.Length - 1; i >= 0; --i) { + cost[i] += Math.Min(Get(i + 1), Get(i + 2)); + } + + return Math.Min(cost[0], cost[1]); + } +}