Skip to content

Commit 0a8b251

Browse files
committed
[2023-11-15] '피보나치 수' 풀이(v2)
1 parent 61fe895 commit 0a8b251

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

Programmers/Step2/피보나치 수.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
def solution(num):
2-
if num == 1 or num == 2:
3-
return 1
4-
bottom_up = [0] * (num + 1)
5-
bottom_up[1] = 1
6-
bottom_up[2] = 1
7-
for i in range(3, num + 1):
8-
bottom_up[i] = (bottom_up[i-1] + bottom_up[i-2]) % 1234567
9-
return bottom_up[-1]
1+
def solution(n):
2+
dp = [0] * 100001
3+
dp[1] = 1
4+
for i in range(2, n+1):
5+
dp[i] = (dp[i-1] + dp[i-2]) % 1234567
6+
return dp[n]

0 commit comments

Comments
 (0)