70. Climbing Stairs

    技术2022-07-10  133

    public int climbStairs(int n) { if (n <= 0) return 0; if (n == 1) return 1; if (n == 2) return 2; int prevPrev = 1; int prev = 2; int curr = 0; for (int i = 3; i <= n; i++) { curr = prev + prevPrev; prevPrev = prev; prev = curr; } return curr; }
    Processed: 0.068, SQL: 9