카테고리 없음
[기타] 피보나치 수열 문제의 함정.....
나스닥171819
2019. 9. 11. 23:26
728x90
반응형
[Programmers/프로그래머스] 피보나치 수 JAVA
문제 설명피보나치 수는 F(0) = 0, F(1) = 1일 때, 1 이상의 n에 대하여 F(n) = F(n...
blog.naver.com
이건 c#
public class Solution {
public int solution(int n) {
int answer = 0;
if(n == 1 || n == 2) return 1; // @1
int n1 = 1, n2 = 1, sum = 0; // @2
for(int i=3; i<=n; i++) { // @3
sum = n1 + n2;
sum %= 1234567;
n1 = n2;
n2 = sum;
}
return sum;
// return answer;
}
}
https://codedrive.tistory.com/70
[Programmers]Lv 2. 피보나치 수
문제: 피보나치 수는 F(0)=0, F(1)=1일 때, 1 이상의 n에 대하여 F(n)=F(n-1)+F(n-2) 가 적용되는 수 입니다. 예를 들어 F(2)= F(0)+F(1)=0+1=1 F(3)= F(1)+F(2)=1+1=2 F(4)= F(2)+F(3)=1+2=3 F(5)= F(3)+F(4)=2+3..
codedrive.tistory.com
반응형