Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 12. 12. 23:45

https://leetcode.com/problems/climbing-stairs/

 

Climbing Stairs - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

완전 탐색이 가능한 문제 (N이 작음)
lru_cache라는걸 쓰면 효율이 좀 더 늘어나는 듯

class Solution:
    @lru_cache(None)
    def climbStairs(self, n: int) -> int:
        return 1 if n < 2 else self.climbStairs(n-1) + self.climbStairs(n-2)
반응형