Write the transition
Standard · Fill in the code · about 6 min
Complete the min cost climbing stairs function. dp[i] is the cheapest cost to stand on step i, and the top is step n.
Fill the three blanks.
Example 1
Input:
[[10,15,20]]
Output:
15
Start on step 1, pay 15, jump to the top.
Example 2
Input:
[[1,100,1,1,1,100,1,1,100,1]]
Output:
6
Constraints
- 1 ≤ cost.length ≤ 1,000
- 0 ≤ cost[i] ≤ 999
Learn the idea first: The DP recipe: state, transition, base cases, order, answer, a visual lesson.
More The DP recipe: state, transition, base cases, order, answer problems
- Identify the state Warm-up
- Min cost climbing stairs Standard
- Fill the min-cost table Standard
- Stair points Standard
- Apply the recipe to a new problem: house robber Challenge