Climbing Stairs

Dynamic Programming
Easy

Approach

Diagrams

Analysis

Time

O(n)

Space

O(n)
class Solution:
    def climbStairs(self, numSteps):
        dp = [0] * (numSteps + 1)
        dp[0] = 1
        possibleSteps = [1, 2]

        for stepCurrentlyOn in range(len(dp)):
            for stepTaken in possibleSteps:
                if stepCurrentlyOn - stepTaken >= 0:
                    dp[stepCurrentlyOn] += dp[stepCurrentlyOn - stepTaken]

        return dp[-1]

Learn

#Dynamic Programming

#Ways

Videos