假设有n个阶梯,每次可以爬1阶或者2阶,有多少种方法
x0=0,x1=1,x2=2,x3=3=x2+x1,和上学时的数列通项公式差不多
var climbStair = function (n) {
let dp = [];
dp[0] = 0, dp[1] = 1, dp[2] = 2;
for (let i = 3; i <= n; i++) {
dp[i] = dp[i - 1] + dp[i - 2]
}
return dp[n]
}
console.log(climbStair(8));