Coding test/programmers - single

[leetcode] 70. Climbing Stairs

engine 2022. 4. 2. 23:58
class Solution:
    def climbStairs(self, n: int) -> int:
        if n < 3:
            return n
        else :
            return self.climbStairs(n-1) + self._climbStairs(n-2)
        
    def _climStairs(self, n: int):
        if n not in self.cache.keys() :
            self.cache[n] = self.climbStairs(n)
        return self.cache[n]