Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 385 Bytes

File metadata and controls

25 lines (20 loc) · 385 Bytes

Climbing Stairs

Solution 1: DP

// TC: O(n)
// SC: O(n)
class Solution {
    public int climbStairs(int n) {
        if (n == 1) {
            return 1;
        }

        int[] mem = new int[n];
        mem[0] = 1;
        mem[1] = 2;

        for (int i = 2; i < n; i++) {
            mem[i] = mem[i - 1] + mem[i - 2];
        }

        return mem[n - 1];
    }
}