Difficult:Easy
題目
You are climbing a staircase. It takes n steps to reach the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
翻譯
你正在爬樓梯。到達頂峰需要 n 步。
每次您可以爬 1 或 2 級台階。你可以通過多少種不同的方式爬上頂峰?
範例
Example 1
1 | Input: n = 2 |
Example 2
1 | Input: n = 3 |
解題思路
1.動態規劃 走到N的走法為n-1或n-2得出f(n)=f(n-1)+f(n-2)
Solution
Code 1 :
1 | let arr=[]; |