当前位置:网站首页>力扣-746.使用最小花费爬楼梯
力扣-746.使用最小花费爬楼梯
2022-04-23 16:03:00 【Node_Su】
题目看不太懂,站在0和1的时候是不用花费的?
dp[i]表示到达当前楼梯 i 时候的最小花费
class Solution(object):
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
n = len(cost)
dp = [0] * (n + 1)
for i in range(2, n + 1):
dp[i] = min(cost[i - 1] + dp[i - 1], cost[i - 2] + dp[i - 2])
return dp[n]
if __name__ == '__main__':
cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
Sol = Solution()
res = Solution.minCostClimbingStairs(Sol, cost)
print(res)
版权声明
本文为[Node_Su]所创,转载请带上原文链接,感谢
https://blog.csdn.net/Node_Su/article/details/124361830
边栏推荐
猜你喜欢
安装Redis并部署Redis高可用集群
GRBL学习(一)
OAK-D树莓派点云项目【附详细代码】
R语言中实现作图对象排列的函数总结
C, calculation method and source program of bell number
Pgpool II 4.3 Chinese Manual - introductory tutorial
[open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
Spark 算子之filter使用
Spark 算子之distinct使用
5 minutes, turn your excel into an online database, the magic cube net table Excel database
随机推荐
实现缺省页面
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
ESP32编译环境的搭建
Es common query, sorting and aggregation statements
Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?
Meaning and usage of volatile
通过Feign在服务之间传递header请求头信息
C language --- advanced pointer
How do you think the fund is REITs? Is it safe to buy the fund through the bank
[split of recursive number] n points K, split of limited range
volatile的含义以及用法
Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
Go language, condition, loop, function
Matplotlib tutorial 05 --- operating images
VIM specifies the line comment and reconciliation comment
Application case of GPS Beidou high precision satellite time synchronization system
Timing model: gated cyclic unit network (Gru)
R语言中绘制ROC曲线方法二:pROC包
Unity shader learning
Groupby use of spark operator