Skip to content

Commit adbafb6

Browse files
authored
Create Solution3.cpp
1 parent d9c7fd1 commit adbafb6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int minCostClimbingStairs(vector<int>& cost) {
4+
int f = 0, g = 0;
5+
for (int i = 2; i <= cost.size(); ++i) {
6+
int gg = min(f + cost[i - 2], g + cost[i - 1]);
7+
f = g;
8+
g = gg;
9+
}
10+
return g;
11+
}
12+
};

0 commit comments

Comments
 (0)