Skip to content

Commit 9d94836

Browse files
committed
[level 2] Title: 피보나치 수, Time: 1.77 ms, Memory: 91.8 MB -BaekjoonHub
1 parent 3dfa777 commit 9d94836

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

프로그래머스/2/12945. 피보나치 수/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 73 MB, 시간: 3.74 ms
7+
메모리: 91.8 MB, 시간: 1.77 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 07월 25일 18:19:03
19+
2025년 09월 11일 19:06:30
2020

2121
### 문제 설명
2222

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
class Solution {
2-
public int solution(int n) {
3-
int answer = 0;
4-
long[] pib=new long[n+1];
5-
pib[0]=0L;
6-
pib[1]=1L;
7-
int times=1;
8-
for(int i=2; i<=n; i++){
9-
pib[i]=(pib[i-1]+pib[i-2])%1234567L;
2+
public int solution(int n) {
3+
int answer = 1;
4+
int f1 = 0, f2 = 1;
5+
6+
for(int i = 2; i<=n; i++){
7+
answer = (f1 + f2)%1234567;
8+
f1 = f2;
9+
f2 = answer;
1010
}
11-
//answer=(int)(pib[n]%1234567L);
12-
answer=(int)(pib[n]);
11+
12+
//if(n>=2) answer %= 1234567;
1313
return answer;
1414
}
1515
}

0 commit comments

Comments
 (0)