'프로그래머스 기능개발'에 해당되는 글 1건

  1. 2020.06.03 프로그래머스 - 기능개발

 

import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        
        Queue<Integer> q = new LinkedList();
        
        //남은 작업 일수
        for(int i =0; i<progresses.length; i++){
            int re = 100 - progresses[i];
            int s = speeds[i];
            int d = re / s;
            if(re % s != 0){
                d++;
            }        
            q.offer(d);
        }
        
        
        int[] tmp = new int[q.size()];
        int sd = 0;//배포일
        int count = 0;
        int idx = 0;
        //작업 순서대로 배포날짜를 체크
        while(q.peek() != null){
            int dd = q.poll();
            
            if(sd == 0){
                sd = dd;
                tmp[idx] = ++count;
                continue;
            }
            
            if(sd >= dd){//후행작업의 배포가능날짜가 작으면 현재 작업과 같이 배포(동시배포 개수 증가)               
                tmp[idx] = ++count;
            }else{//후행작업의 배포가능날짜가 크면 늦게 배포(동시 배포 개수 초기화)
                idx++;
                count = 0;
                sd = dd;
                tmp[idx] = ++count;
            }
            
        }
        
        int[] answer = new int[idx+1];
        for(int i =0; i<answer.length; i++){
            answer[i] = tmp[i];
        }
        
        return answer;
    }
}

'개발 > CodingTest' 카테고리의 다른 글

Hacckerrank - Halloween Sale  (0) 2020.06.25
Hackerrank - Prime Checker  (0) 2020.06.05
프로그래머스 - 탑  (0) 2020.06.03
HackerRank - Anagrams  (0) 2020.06.02
HackerRank - Counting Valley  (0) 2020.06.01
Posted by Lumasca
,