当前位置:网站首页>力扣-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
边栏推荐
猜你喜欢

5 minutes, turn your excel into an online database, the magic cube net table Excel database

Groupby use of spark operator

安装Redis并部署Redis高可用集群

Large factory technology implementation | industry solution series tutorials

Review 2021: how to help customers clear the obstacles in the last mile of going to the cloud?

Countdown 1 day ~ 2022 online conference of cloud disaster tolerance products is about to begin

5分钟,把你的Excel变成在线数据库,神奇的魔方网表excel数据库

Ice -- source code analysis

Distinct use of spark operator

建设星际计算网络的愿景
随机推荐
The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
C#,贝尔数(Bell Number)的计算方法与源程序
matplotlib教程05---操作图像
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
捡起MATLAB的第(6)天
Using JSON server to create server requests locally
Go language slice, range, set
Ice -- source code analysis
捡起MATLAB的第(4)天
Meaning and usage of volatile
Research and Practice on business system migration of a government cloud project
Import address table analysis (calculated according to the library file name: number of imported functions, function serial number and function name)
下载并安装MongoDB
Do we media make money now? After reading this article, you will understand
C, calculation method and source program of bell number
多线程原理和常用方法以及Thread和Runnable的区别
PS为图片添加纹理
Day (2) of picking up matlab
Groupby use of spark operator
Vim使用Vundle安装代码补全插件(YouCompleteMe)