当前位置:网站首页>leetcode746. Climb stairs with minimum cost (simple)
leetcode746. Climb stairs with minimum cost (simple)
2022-04-22 14:48:00 【Heavy garbage】



It's similar to the idea of climbing stairs .
leetcode70. climb stairs ( Simple ):https://blog.csdn.net/zhangjiaji111/article/details/121801918
Ideas :dp
dp[i] To i The lowest cost of the steps in the position
dp[n]=min(dp[n-1]+cost[n-1],dp[n-2]+cost[n-2])
The border :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];
}
};
版权声明
本文为[Heavy garbage]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204221445202983.html
边栏推荐
- php 一维数组去重
- 若依同时集成jsp和thymeleaf解决方案
- Android性能优化 _ 帧动画OOM?优化帧动画之SurfaceView逐帧解析,阿里P8面试官都说太详细了
- C install opencv
- Sonar of code coverage
- 985 Shuo's difficult transition to Android, plus face-to-face experience sharing, meituan Android interview
- Arcpy development environment configuration
- vscode settings.json位置
- Introduction to openvino
- 【ELT.ZIP】OpenHarmony啃论文成长计划——多维探秘通用无损压缩
猜你喜欢

Android 开发艺术探索笔记(23),2022年Android高级面试题总结
![[elt.zip] openharmony's paper growth plan -- multidimensional exploration and universal lossless compression](/img/76/73c92acd32a51aa6e054da44205e23.png)
[elt.zip] openharmony's paper growth plan -- multidimensional exploration and universal lossless compression

vscode settings. JSON location
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

阿里云IoT流转到postgresql数据库方案

中国 AI 的“黄埔军校”?MSRA 被曝停招“国防七子”及北邮学生

vscode settings.json位置

Static routing comprehensive experiment

带你了解极具弹性的Spark架构的原理

C#安装opencv
随机推荐
leetcode746. 使用最小花费爬楼梯(简单)
升级了源端数据库到5.0版本,重启mongoshake服务,然后报错了
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
SQL Server 数据库之常量
Gradle references peer projects
datagrip连接Mysql报错[08001] Public Key Retrieval is not allowed.
机器学习模型融合大法!
【ORB_SLAM2源码解读】分析ORB_SLAM2 RGBD 第0帧是怎么计算位置姿态的
自动化测试的生命周期是什么?
带你了解极具弹性的Spark架构的原理
【ELT.ZIP】OpenHarmony啃论文俱乐部——综述视角解读压缩编码
Crossplane - 比 Terraform 更先进的云基础架构管理平台?
memcpy( )函数复制二维数组 & memcmp( )函数比较二维数组
【 elt.zip】 The Outlook of CCF open source University Bank phase I
若依同时集成jsp和thymeleaf解决方案
【C语言】C语言的基本概念
Archengine custom tool mouse style settings
It people should not only improve their earning ability, but also expand their ways of making money. The "immortal document" released by Tencent's technical officer is a hot network
Rip introduction
Introduction to openvino