Min Cost Climbing Stairs
EasyP2Coding
cost[i] is the price of standing on step i and leaving it. Once you pay, you may climb one or two steps. You may start on step 0 or step 1. The top is one position past the last step.
Return the minimum total price to reach the top.
Example 1
- Input
- cost = [10,15,20]
- Output
- 15
- Why
- Start on step 1, pay 15 and jump to the top.
Example 2
- Input
- cost = [1,100,1,1,1,100,1,1,100,1]
- Output
- 6
Example 3
- Input
- cost = [0,0]
- Output
- 0
Constraints
- 2 <= cost.length <= 1000
- 0 <= cost[i] <= 999
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.