문제
나의 생각
front에 있는 숫자가 100을 넘어야 뒤에 100이 넘는 수가 연속적으로 있는 것들이 출력이 가능하다.
그리고 그 빠져나가는 데이터의 수를 기록 할 수 있는 List를 사용할 것이다.
LinkedList로 Queue를 구현을 하면 get(), set()함수로 데이터 빼고 넣고 할 필요 없이 index로 더하기가 가능하다.
나의 답안
public static int[] solution(int[] progresses, int[] speeds) {
LinkedList<Integer> queue = new LinkedList<>();
LinkedList<Integer> speedQ = new LinkedList<>();
ArrayList<Integer> countList = new ArrayList<>();
for (int i : progresses) queue.offer(i);
for (int i : speeds) speedQ.offer(i);
System.out.println(queue);
System.out.println(speedQ);
while (!queue.isEmpty()) {
int count = 0;
while (queue.peek() >= 100) {
queue.poll();
speedQ.poll();
count++;
if (queue.size() == 0) break;
}
if (count > 0) countList.add(count);
for (int i = 0; i < queue.size(); i++) {
queue.set(i, queue.get(i) + speedQ.get(i));
}
}
return countList.stream().mapToInt(Integer::intValue).toArray();
}
'Programmers 문제풀이 > Lv.2' 카테고리의 다른 글
올바른 괄호 (0) | 2023.03.26 |
---|---|
최솟값 만들기 (0) | 2023.03.26 |
JadenCase 문자열 만들기 (0) | 2023.03.26 |
최댓값과 최솟값 (0) | 2023.03.26 |
프린터 (0) | 2023.03.17 |