Today I Learned

[프로그래머스] 스택/큐 Level 2. 기능개발(JAVA) 본문

알고리즘 & 코딩테스트

[프로그래머스] 스택/큐 Level 2. 기능개발(JAVA)

하이라이터 2021. 1. 31. 03:31
728x90

개발기간은 Math.ceil 함수로 올림하여 계산

다음 배포일 이내 개발건들을 카운트하여 배포목록에 추가

 

코드

import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        ArrayList<Integer> deployList = new ArrayList<Integer>();

        int deployCnt = 0;
        int nextDeploy = 0;
        for(int i = 0; i < progresses.length; i++){
            int period = (int)Math.ceil((100-progresses[i]) / (double)speeds[i]);
            System.out.println(period);

            if(nextDeploy == 0){ //최초 배포일
                deployCnt = 1;
                nextDeploy = period;
                continue;
            }

            if(nextDeploy < period){ //다음 배포일로 넘김
                nextDeploy = period;
                deployList.add(deployCnt);
                deployCnt = 1; //배포건 수 초기화
            }else{ //기존 배포건 수에 추가
                deployCnt++;
            }
        }
        deployList.add(deployCnt);//마지막 배포일 추가

        int[] answer = new int[deployList.size()];
        for(int i = 0; i < deployList.size(); i++){
            answer[i] = deployList.get(i);
        }
        return answer;
    }
}

 

결과

점수는 6점

다른 풀이는 생략

728x90
Comments