题解 | #爬楼梯#

爬楼梯

https://www.nowcoder.com/practice/b178fcef3ed4448c99d7c0297312212d

大数字问题使用 JavaScript 的 BigInt 类型解决。

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void async function () {
    // Write your code here
    function Solution(top){
      let stepMemory = Array.from(new Array(top + 1).fill(1n))
      for(let i = 2; i < top + 1; i++){
        stepMemory[i] = BigInt(stepMemory[i - 1]) + BigInt(stepMemory[i - 2])
      }

      return stepMemory[top].toString()
    }
    while(line = await readline()){
        let tokens = line.split(' ');
        let a = parseInt(tokens[0]);

        console.log(Solution(a));
    }
}()

全部评论

相关推荐

认真搞学习:这么良心的老板真少见
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务