원본 : https://school.programmers.co.kr/learn/courses/30/lessons/12900
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
class Solution {
public int solution(int n) {
int num1 = 1;
int num2 = 2;
if (n == 1) {
return 1;
}
if (n == 2) {
return 2;
}
int result = 0;
for (int i = 3; i <= n; i++) {
result = (num1 + num2) % 1000000007;
num1 = num2;
num2 = result;
}
return result;
}
}
다리를 지나는 트럭 (스택/큐) (0) | 2022.07.11 |
---|---|
위장 (해시) (0) | 2022.07.11 |
배달 (Summer/Winter Coding(~2018)) (0) | 2022.07.08 |
후보키 (2019 KAKAO BLIND RECRUITMENT) (0) | 2022.07.08 |
조이스틱 (탐욕법(Greedy)) (0) | 2022.07.08 |
댓글 영역