# 爬楼梯

有一楼梯共M级，刚开始时你在第一级，若每次只能跨上一级或二级，要走上第M级，共有多少种走法？

**分析**： 这个问题要倒过来看，要到达n级楼梯，只有两种方式，从（n-1）级 或 （n-2）级到达的。所以可以用递推的思想去想这题，假设有一个数组s\[n], 那么s\[1] = 1（由于一开始就在第一级，只有一种方法）， s\[2] = 1（只能从s\[1]上去 没有其他方法）。

那么就可以推出s\[3] \~ s\[n]了。

下面继续模拟一下， s\[3] = s\[1] + s\[2]， 因为只能从第一级跨两步， 或者第二级跨一步。

```
function cStairs(n) {
    if(n === 1 || n === 2) {
        return 1;
    } else {
        return cStairs(n-1) + cStairs(n-2)
    }
}
复制代码
```

嗯嗯，没错呢，其实就是斐波纳契数列没跑了


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mm.ricky.moe/algorithm/algorithm-and-data-structure/di-gui/pa-lou-ti.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
