题解 | #跳台阶#
跳台阶扩展问题
http://www.nowcoder.com/practice/953b74ca5c4d44bb91f39ac4ddea0fee
先写出前几项得出规律除了第一项为0,剩下的每一项都是前一项2倍;
const m = parseInt(readline());
const getMethod = (n) =>{
if(n == 0){
return 0;
}else if(n == 1){
return 1;
}else if(n == 2){
return 2;
}
// else if(n == 3){
// return 4
// }else if(n == 4){
// return 8;
// }
else{
var arr = [0,1,2]
for(var i = 3; i <= n; i++){
arr.push(arr[i-1]*2)
}
return arr[n]
}
}
console.log(getMethod(m))