Skip to content

Commit fd82790

Browse files
authored
Create Solution3.java
1 parent 5242505 commit fd82790

File tree

1 file changed

+11
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)