728x90
package prog;
import java.util.*;
public class 기능개발 {
public static void main(String[] args) {
Solution_기능개발 s = new Solution_기능개발();
System.out.println(Arrays.toString(s.solution(new int[]{93, 30, 55}, new int[]{1, 30, 5})));
System.out.println(Arrays.toString(s.solution(new int[]{95, 90, 99, 99, 80, 99}, new int[]{1, 1, 1, 1, 1, 1})));
}
}
class Solution_기능개발 {
public int[] solution(int[] progresses, int[] speeds) {
int[] answer ;
Queue<Integer> answerQ = new LinkedList<Integer>();
int idx=0;
int cnt=0;
while(idx!=progresses.length){
if(progresses[idx]>=100){
idx++;
cnt++;
}
else{
// answer 추가
if(cnt!=0){
answerQ.add(cnt);
cnt=0;
}
// progresses 증가
else{
for (int i = idx; i < progresses.length; i++) {
progresses[i]+= speeds[i];
}
}
}
}
answerQ.add(cnt);
answer = new int[answerQ.size()];
int length=answerQ.size();
for (int i = 0; i < length; i++) {
answer[i] = answerQ.poll();
}
return answer;
}
}
728x90
'알고리즘 > 프로그래머스' 카테고리의 다른 글
더 맵게 (자바) (0) | 2021.09.08 |
---|---|
타겟넘버 (자바) (0) | 2021.09.08 |
124 나라의 숫자 (자바) (0) | 2021.09.06 |
멀쩡한 사각형 (자바) (0) | 2021.09.06 |
단체사진찍기 (0) | 2021.09.04 |