We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eb05caf commit 8392986Copy full SHA for 8392986
Easy/Min Cost Climbing Stairs.java
@@ -1,13 +1,12 @@
1
class Solution {
2
- public int minCostClimbingStairs(int[] cost) {
3
- int n = cost.length;
4
- int first = cost[0];
5
- int second = cost[1];
6
- for (int i = 2; i < n; i++) {
7
- int curr = cost[i] + Math.min(first, second);
8
- first = second;
9
- second = curr;
+ public int minCostClimbingStairs(int[] cost) {
+ int stepOneCost = cost[0];
+ int stepTwoCost = cost[1];
+ for (int i = 2; i < cost.length; i++) {
+ int currCost = cost[i] + Math.min(stepOneCost, stepTwoCost);
+ stepOneCost = stepTwoCost;
+ stepTwoCost = currCost;
+ }
10
+ return Math.min(stepOneCost, stepTwoCost);
11
}
- return Math.min(first, second);
12
- }
13
0 commit comments