https://school.programmers.co.kr/learn/courses/30/lessons/12900
문제 분류 : 코딩테스트 연습 > 연습문제 > 2 x n 타일링
난이도 : 2
정답 코드
class Solution {
public int solution(int n) {
if(n == 1) return 1;
if(n == 2) return 2;
long DP [] = new long [n+1];
DP[1] = 1; DP[2] = 2;
for(int i = 3; i <= n; i++){
DP[i] = (DP[i-1] + DP[i-2]) % 1000000007;
}
return (int)DP[n];
}
}
'Algorithm > Programmers Java' 카테고리의 다른 글
Java 프로그래머스 배달 (0) | 2024.02.29 |
---|---|
Java 프로그래머스 피보나치 수 (0) | 2024.02.29 |
Java 프로그래머스 최댓값과 최솟값 (0) | 2024.02.29 |
Java 프로그래머스 게임 맵 최단거리 (0) | 2024.02.29 |
Java 프로그래머스 최솟값 만들기 (0) | 2024.02.29 |