Algorithm/Programmers Java

Java 프로그래머스 2 x n 타일링

제우제우 2024. 2. 29. 16:12

https://school.programmers.co.kr/learn/courses/30/lessons/12900

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

문제 분류 : 코딩테스트 연습 > 연습문제 > 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];
    }
}