bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 746. Min Cost Climbing Stairs

746. Min Cost Climbing Stairs

Leetcode Solutions

Approach: Bottom-Up Dynamic Programming (Tabulation)

  1. Initialize an array minimumCost with a length of cost.length + 1, and set the first two elements to 0 (base cases).
  2. Iterate over the array starting from the third element (index 2).
  3. For each step i, calculate minimumCost[i] using the recurrence relation: minimumCost[i] = min(minimumCost[i - 1] + cost[i - 1], minimumCost[i - 2] + cost[i - 2]).
  4. After filling the table, return the last element of minimumCost, which represents the minimum cost to reach the top of the floor.
UML Thumbnail

Approach: Bottom-Up, Constant Space

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...