Skip to content

Commit fe2f068

Browse files
authored
Create Solution.java
1 parent c61c00f commit fe2f068

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 int minCostClimbingStairs(int[] cost) {
3+
int pre1 = 0, pre2 = 0;
4+
int res = 0;
5+
for (int i = 2; i <= cost.length; ++i) {
6+
res = Math.min(pre1 + cost[i - 1], pre2 + cost[i - 2]);
7+
pre2 = pre1;
8+
pre1 = res;
9+
}
10+
return res;
11+
}
12+
}

0 commit comments

Comments
 (0)