파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 7. 6. 23:45

https://leetcode.com/problems/fibonacci-number/

 

Fibonacci Number - 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

이건 뭐.. 거의 정석과도 같은 메모이제이션으로 풀 수 있는 문제.
구구단 급..이라고 해야 할까 ㅋㅋ

class Solution:
    def fib(self, n: int) -> int:
        fi = [0] * 31
        fi[1] = fi[2] = 1
        for i in range(3, 31):
            fi[i] = fi[i-2] + fi[i-1]        
        return fi[n]
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.07.08
Today's Challenge  (0) 2022.07.07
Today's Challenge  (0) 2022.07.05
Today's Challenge  (0) 2022.07.04
Today's Challenge  (0) 2022.07.03
Comments