Seventy-five days: force buckle 746, use minimum cost to climb stairs

Address: leetcode-cn.com/problems/mi…

The minimum value of each level is added to the minimum value of the previous level or the previous level, so dynamic programming can be easily solved.

function minCostClimbingStairs(cost: number[]): number {
  let res:Array<number> = new Array(cost.length + 1);
  res[0] = 0;
  res[1] = 0;
  for(let i:number = 2; i < cost.length + 1; i++)
  {
    res[i] = Math.min(res[i - 1] + cost[i - 1], res[i - 2] + cost[i - 2]);
  }
  return res[cost.length];
};
Copy the code

Execution time: 96 ms, beating 66.67% of all TypeScript commits

Memory consumption: 40.8 MB, beating 38.89% of all TypeScript commits