Same simple algorithm written in every offered language. Variable `a`

tells you the number of ways to reach the current step, and `b`

tells you the number of ways to reach the next step. So for the situation one step further up, the old `b`

becomes the new `a`

, and the new `b`

is the old `a+b`

, since that new step can be reached by climbing 1 step from what `b`

represented or 2 steps from what `a`

represented.

Ruby wins, and *"the C languages"* all look the same.

**Ruby** (60 ms)

```
def climb_stairs(n)
a = b = 1
n.times { a, b = b, a+b }
a
end
```

**C++** (0 ms)

```
int climbStairs(int n) {
int a = 1, b = 1;
while (n--)
a = (b += a) - a;
return a;
}
```

**Java** (208 ms)

```
public int climbStairs(int n) {
int a = 1, b = 1;
while (n-- > 0)
a = (b += a) - a;
return a;
}
```

**Python** (52 ms)

```
def climbStairs(self, n):
a = b = 1
for _ in range(n):
a, b = b, a + b
return a
```

**C** (0 ms)

```
int climbStairs(int n) {
int a = 1, b = 1;
while (n--)
a = (b += a) - a;
return a;
}
```

**C#** (48 ms)

```
public int ClimbStairs(int n) {
int a = 1, b = 1;
while (n-- > 0)
a = (b += a) - a;
return a;
}
```

**Javascript** (116 ms)

```
var climbStairs = function(n) {
a = b = 1
while (n--)
a = (b += a) - a
return a
};
```