Problem
On a staircase, the i
-th step has some non-negative cost cost[i]
assigned (0 indexed).
Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.
Examples
1 | Input: cost = [10, 15, 20] |
1 | Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1] |
Solution
Method: Dynamic Programming
Time Complexity: O(n)
Space Complexity: O(n)
1 | class Solution: |
Reference
https://leetcode.com/problems/min-cost-climbing-stairs/solution/