title: "[프로그래머스] 피보나치 수 Python 파이썬 해설 (Level 2) - 이도훈"
cleanUrl: "programmers/12945"
description: "프로그래머스 Level 2 문제 [피보나치 수]의 풀이를 정리합니다."

문제 설명 및 제한사항

아이디어 및 해결 방법

코드

import sys; sys.setrecursionlimit(1000000)
cache = {0:0, 1:1, 2:1}

def fib(n):
    if n in cache:
        return cache[n]
    
    v = fib(n-1) + fib(n-2)
    cache[n] = v % 1234567
    
    return cache[n]

def solution(n):
    return fib(n)

출처

프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges