-
爬楼梯
思路:n = (n-1) + (n-2)
function climbStairs(n: number): number { if(n<=2){ return n } let i = 1; let j = 2 for(let k= 3;k<=n; k++){ const n1 = i+j i= j j= n1 } return j };
爬楼梯-typescript
最新推荐文章于 2024-11-17 06:32:34 发布
爬楼梯
思路:n = (n-1) + (n-2)
function climbStairs(n: number): number {
if(n<=2){
return n
}
let i = 1;
let j = 2
for(let k= 3;k<=n; k++){
const n1 = i+j
i= j
j= n1
}
return j
};