프로그래머스 기능개발(JAVA)

윤희영·2022년 7월 19일
0

풀이과정


처음에는 그냥 포문으로 비교할까 했는데 문제 유형이 큐를 이용하라고 해서 배열에 넣는게 아니라 큐에넣었다.


코드


import java.util.*;
class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        int[]arr = new int[progresses.length];
        ArrayList<Integer>a = new ArrayList<Integer>();
        Queue<Integer>b = new LinkedList<>();
        for(int i = 0; i<progresses.length; i++){
            b.add((int)Math.ceil((double)(100-progresses[i])/speeds[i]));
        }
        
        int cnt = 1;        
        int front = b.poll();
        while(!b.isEmpty()){
            if(front<b.peek()){
                a.add(cnt);
                cnt=1;
                front = b.poll();                
            }else{
                cnt++;
                b.poll();//프론트는 가장 높은 값을 고정하고 그 이후값만 비교하기때문.
            }
        }
        a.add(cnt);
        return a.stream().mapToInt(Integer::intValue).toArray();
    }
}
profile
특별

0개의 댓글

관련 채용 정보