https://school.programmers.co.kr/learn/courses/30/lessons/42586
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
Queue<Integer> queue = new LinkedList<>();
Queue<Integer> squeue = new LinkedList<>();
for(int i : progresses){
queue.add(i);
}
for(int i : speeds){
squeue.add(i);
}
Stack<Integer> stack = new Stack<>();
while(queue.size() >= 1){
int cnt = 0;
for(int i = 0; i < queue.size(); i++){
int speed = squeue.poll();
queue.add(queue.poll()+speed);
squeue.add(speed);
}
while (!queue.isEmpty() && queue.peek() >= 100) {
queue.poll();
squeue.poll();
cnt++;
}
if(cnt > 0){
stack.push(cnt);
}
}
int[] answer = new int[stack.size()];
for(int i = 0; i < stack.size(); i++){
answer[i] = stack.get(i);
}
return answer;
}
}
/*
1. queue를 사용해서 남은 progresses, speeds를 관리
2. 큐가 빌 때까지 개발 반복
3. 첫번째 기능의 개발이 완료되면 뒤 기능도 체크하여 같이 삭제
4. stack에 각 배포마다 개발 기능 수 저장하고 마지막에 배열로 옮겨 반환
*/'코딩테스트 > 코딩테스트 문제풀이' 카테고리의 다른 글
| [Java] 프로그래머스 <멀리 뛰기> (0) | 2025.03.08 |
|---|---|
| [Java] 프로그래머스 <프로세스> (0) | 2025.03.07 |
| [Java] 프로그래머스 <더 맵게> (0) | 2025.03.07 |
| [Java] 프로그래머스 <시저 암호> (0) | 2025.03.06 |
| [Java] 프로그래머스 <삼총사> (0) | 2025.03.06 |