0070. Climbing Stairs

70. Climbing Stairs #

题目 #

假定某人正在爬楼梯,需要 n 阶才能到达楼顶。

每次可以爬 12 个台阶。求出爬到楼顶的方案总数。

思路 #

代码 #

class Solution {
    public int climbStairs(int n) {
        if (n == 1 || n == 2) return n;
        int prev = 1, cur = 2;
        for (int i = 3; i <= n; i++) {
            int temp = prev + cur;
            prev = cur;
            cur = temp;
        }
        return cur;
    }
}