프로그래머스_C#/Level_2
[프로그래머스 C#] 피보나치 수
최애뎡
2021. 10. 27. 00:05
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/12945
코딩테스트 연습 - 피보나치 수
피보나치 수는 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) =
programmers.co.kr
using System.Collections.Generic;
public class Solution {
public int solution(int n) {
List<int> _list = new List<int>();
_list.Add(0); _list.Add(1);
for (int i = 1; ++i < n;)
{
int count = _list.Count;
_list.Add(_list[count - 1] % 1234567 + _list[count - 2] % 1234567);
}
return (_list[_list.Count - 1] + _list[_list.Count - 2]) % 1234567;
}
}
악으로 깡으로 나머지..
반응형