code >>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
class Solution {
public:
int minCostClimbingStairs(vector<int>& cost) {
int s = cost[0];
int f = cost[1];
if (cost.size() == 2)
return std::min(s, f);
for (int i = 2; i < cost.size(); i++)
{
int k = std::min(s+cost[i], f+cost[i]);
s = f;
f = k;
}
return std::min(f, s);
}
};
|
'C' 카테고리의 다른 글
c++ leetcode coin change code (0) | 2021.07.27 |
---|---|
leetcode minimum path sum c++ code (0) | 2021.07.27 |
c++ leetcode climbing stairs DP solution(Top-down and bottom-up) (0) | 2021.07.24 |
c++ leetcode 939 minimum rectangle area o(n^2) solution code (0) | 2021.07.24 |
c++ leetcode 525 contiguous array solution (0) | 2021.07.24 |