题目
答案
class Solution:
def minCostClimbingStairs(self, cost: List[int]) -> int:
n = len(cost)
sum = [0]*n
sum[0] = cost[0]
sum[1] = cost[1]
# sum[2] = min(sum[0]+cost[2],sum[1]+cost[2])
# sum[3] = min(sum[3-2]+cost[3],sum[3-1]+cost[3])
for i in range(2,n):
sum[i] = min(sum[i-2]+cost[i],sum[i-1]+cost[i])
return min(sum[-1],sum[-2])