Algorithm/1일 1코테
[🤷♀️ Leetcode] 509. Fibonascci Number
대인보우
2020. 11. 9. 14:39
반응형
문제설명
피보나치 수를 구하라
leetcode.com/problems/fibonacci-number/submissions/
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:
dp = collections.defaultdict(int)
def fib(self, N: int) -> int:
if N<=1:
return N
if self.dp[N]:
return self.dp[N]
self.dp[N] = self.fib(N-1) + self.fib(N-2)
return self.dp[N]
반응형