본문 바로가기
알고리즘 & 자료구조/프로그래머스

피보나치 수

by 신재권 2022. 12. 31.
package programmers;

public class 피보나치수 {

   public static int solution(int n) {
      int[] D = new int[n + 1];
      D[0] = 0;
      D[1] = 1;
      for (int i = 2; i <= n; i++) {
         D[i] = (D[i - 1] + D[i - 2]) % 1234567;
      }

      return D[n];
   }

   public static void main(String[] args) {
      System.out.println(solution(3));
      System.out.println(solution(5));
   }
}

'알고리즘 & 자료구조 > 프로그래머스' 카테고리의 다른 글

카펫  (0) 2023.01.02
다음 큰 숫자  (0) 2023.01.01
숫자의 표현  (0) 2022.12.30
이진 변환 반복하기  (0) 2022.12.29
올바른 괄호  (0) 2022.12.28