Keep track of the optimal sums for the latest two steps.

Ruby version:

```
def min_cost_climbing_stairs(cost)
cost.reduce([0]) { |s, c| [c + s.min, s[0]] }.min
end
```

Python version:

```
def minCostClimbingStairs(self, cost):
return min(reduce(lambda s, c: [c + min(s), s[0]], cost, [0]))
```

For-loop version:

```
def minCostClimbingStairs(self, cost):
s = [0]
for c in cost:
s = c + min(s), s[0]
return min(s)
```

Java version:

```
public int minCostClimbingStairs(int[] cost) {
int a = 0, b, min = 0;
for (int c : cost) {
b = a;
a = c + min;
min = Math.min(a, b);
}
return min;
}
```

C++ version:

```
int minCostClimbingStairs(vector<int>& cost) {
int a = 0, b, result = 0;
for (int c : cost) {
b = a;
a = c + result;
result = min(a, b);
}
return result;
}
```