70. 爬楼梯

2019-12-29  本文已影响0人  Andysys
    // 斐波那契数
    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;
    }
上一篇 下一篇

猜你喜欢

热点阅读