美文网首页
70. 爬楼梯

70. 爬楼梯

作者: Andysys | 来源:发表于2019-12-29 00:22 被阅读0次
        // 斐波那契数
        public int climbStairs(int n) {
            if (n == 1) {
                return 1;
            }
            int first = 1;
            int second = 2;
            int third;
            for (int i = 3; i <= n; i++) {
                third = first + second;
                first = second;
                second = third;
            }
            return second;
        }
    

    相关文章

      网友评论

          本文标题:70. 爬楼梯

          本文链接:https://www.haomeiwen.com/subject/fpbeoctx.html