# 70.爬楼梯

## 题目描述
[70.爬楼梯](https://leetcode.cn/problems/climbing-stairs/)

## 解题思路
本质上与[斐波那契数](https://zwyyy456.vercel.app/zh/posts/tech/509.fibonacci-number/)是一样的：$a_n = a_{n - 1} + a_{n - 2}$
构建`for`循环来遍历。

## 代码
```cpp
class Solution {
  public:
    int climbStairs(int n) {
        int cnt[2] = {1, 1};
        if (n == 1)
            return 1;
        for (int i = 1; i < n; i++) {
            int sum = cnt[0] + cnt[1];
            cnt[0] = cnt[1];
            cnt[1] = sum;
        }
        return cnt[1];
    }
};
```

