当前位置:网站首页>leetcode746. 使用最小花费爬楼梯(简单)
leetcode746. 使用最小花费爬楼梯(简单)
2022-04-22 14:45:00 【重you小垃】



跟爬楼梯思想很类似。
leetcode70.爬楼梯(简单):https://blog.csdn.net/zhangjiaji111/article/details/121801918
思路:dp
dp[i]表示到i位置的台阶的最低花费
dp[n]=min(dp[n-1]+cost[n-1],dp[n-2]+cost[n-2])
边界:dp[0] = dp[1] = 0;
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
int n = cost.size();
vector<int> dp(n + 1);
dp[0] = dp[1] = 0;
for (int i = 2; i <= n; ++i) {
dp[i] = min(dp[i - 1] + cost[i - 1], dp[i - 2] + cost[i - 2]);
}
return dp[n];
}
};
版权声明
本文为[重you小垃]所创,转载请带上原文链接,感谢
https://blog.csdn.net/zhangjiaji111/article/details/124329826
边栏推荐
- MySQL面试题汇总-55题
- C compile BS interface environment deployment and development and debugging methods
- [ELT. Zip] openharmony paper Club - you shouldn't miss these small landscapes
- Android performance optimization_ Frame animation oom? The surfaceview of optimized frame animation is parsed frame by frame. Alibaba P8 interviewers said it was too detailed
- Applying stochastic processes 09: discrete time Martingales
- ITopologicalOperator使用说明
- arcengine 这个集合中找不到此项目
- 【ELT.ZIP】OpenHarmony啃论文俱乐部——细数生活中的压缩点滴
- Fundamentals of database (II)
- Use of logcat
猜你喜欢
随机推荐
分享一个(快捷导航)
How do I copy requests from the Chrome web tab to postman?
Which domestic foreign exchange platforms are safe and formal?
阿里云IoT流转到postgresql数据库方案
vscode settings. JSON location
如何配置 SLO
PCBA/IPQ4019 /openWRT 2.4/5G dual bands IPQ4019 openWRT 2.4/5G dual bands
Is it safe to open a stock account in Nanjing? Is it dangerous?
Upload and download of shared folders on remote server
Archengine custom tool mouse style settings
【C语言】C语言的基本概念
When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that canno
ArcEngine line to face conversion
vscode settings.json位置
Kotlin 匿名函数与函数
智能手表的下半场,机遇与挑战并存
数据库资源负载管理(下篇)
OpenVINO使用介绍
Android 面试:事件分发8连问,安卓基础面试题
@Resource与构造函数踩坑








