❔ Why wrong answer?
So I am trying to resolve this puzzle https://leetcode.com/problems/min-cost-climbing-stairs/?envType=study-plan&envId=level-1&plan=leetcode-75
My progress in the code is as follows:
And it still gets wrothe ng answer (see screenshot). Could anyone kindly point out to me what went wrong with the code?
My progress in the code is as follows:
public class Solution {
public int MinCostClimbingStairs(int[] cost) {
int i;
int[] dp = new int[cost.Length-1];
for(i = 0; i < cost.Length; i++){
if(i < 2){
dp[i] = cost[i];
return dp[i];
} else {
dp[i] += cost[i] + Math.Min(dp[i+1], dp[i+2]);
}
}
return Math.Min(dp[0], dp[1]);
}
}And it still gets wrothe ng answer (see screenshot). Could anyone kindly point out to me what went wrong with the code?


