[프로그래머스/Java] 기능개발

괜찮아요?·2023년 4월 4일
0

programmers

목록 보기
14/23

링크

링크텍스트

코드

import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        ArrayList<Integer> answerList = new ArrayList<Integer>();
        int[] dayCount = new int[progresses.length];
                
        for(int i=0; i<progresses.length; i++){
            while (progresses[i] < 100){
                progresses[i] += speeds[i];
                dayCount[i] += 1;
            }
        }     
        
        int standard = dayCount[0];
        int count = 1;
        for(int i=1; i<dayCount.length; i++){
            if(standard >= dayCount[i]){
                count++;
            }else{
                answerList.add(count);
                standard = dayCount[i];
                count = 1;
            }      
        }
        answerList.add(count);
        
        int[] answer = new int[answerList.size()];
        for(int i=0; i<answerList.size(); i++){
            answer[i] = answerList.get(i);
        }
        return answer;
    }
}
profile
할 수 있어요

0개의 댓글