Climbing Stairs

Brute force:

def climb_stairs(n):
    """
    time: O(2^n)
    space: O(n)
    """
    if n <=2:
        return n

    return  climb_stairs_2(n-1) + climb_stairs_2(n-2)

Tabulation:

Tabulation with better memory usage:

Last updated

Was this helpful?