Skip to content

Latest commit

 

History

History
54 lines (40 loc) · 1.39 KB

_70. Climbing Stairs.md

File metadata and controls

54 lines (40 loc) · 1.39 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : May 22, 2024

Last updated : July 01, 2024


Related Topics : Math, Dynamic Programming, Memoization

Acceptance Rate : 53.43 %


Solutions

Python

class Solution:
    def climbStairs(self, n: int) -> int:
        
        return self.climbStairsBottomUp(0, n)

    @cache
    def climbStairsBottomUp(self, curr: int, n: int) -> int:
        if (curr == n) :
            return 1
        if (curr > n) :
            return 0
        return self.climbStairsBottomUp(curr + 1, n) + self.climbStairsBottomUp(curr + 2, n)
class Solution:
    record = {}
    def climbStairs(self, n: int) -> int:
        if (n == 0 or n == 1) :
            return 1
        if (n not in self.record) :
            self.record[n] = self.climbStairs(n - 1) + self.climbStairs(n - 2)
        return self.record[n]