1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 09:46:57 +02:00

cs: add “746. Min Cost Climbing Stairs”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2024-01-07 19:57:54 +01:00
parent 15e41e476e
commit b6f5b99ee1
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -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]);
}
}