Posted on 2023-10-13 23:19
Uriel 阅读(28)
评论(0) 编辑 收藏 引用 所属分类:
DP 、
闲来无事重切Leet Code
每次可以爬一级或者两级台阶,每级台阶有对应的cost,从第0级或者第1级台阶开始,问爬完台阶的最小花费,简单DP
1 #746
2 #Runtime: 33 ms (Beats 67.69%)
3 #Memory: 13.5 MB (Beats 32.59%)
4
5 class Solution(object):
6 def minCostClimbingStairs(self, cost):
7 """
8 :type cost: List[int]
9 :rtype: int
10 """
11 dp = [0] * (1 + len(cost))
12 for i in range(2, len(cost) + 1):
13 dp[i] = min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2])
14 return dp[-1]