미분류

[알고리즘] 기능 개발

import java.util.*;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) {
        Map<Integer,Integer> returnMap = new LinkedHashMap<>();
        
        int maxFinishIndex = 0;
        for(int i=0;i<progresses.length;i++){
            int p = progresses[i];
            int s = speeds[i];
            
            int time = (int) Math.ceil((100-p)/((double)s));
            maxFinishIndex = Math.max(maxFinishIndex,time);
            
            Integer value = returnMap.get(maxFinishIndex);
            returnMap.put(maxFinishIndex, value!=null?value+1:1);
        }
        
        return returnMap.values().stream().mapToInt(i->i.intValue()).toArray();
    }
}
https://github.com/imkim1893/algorithms/blob/master/%EA%B8%B0%EB%8A%A5%EA%B0%9C%EB%B0%9C.java

Leave a Reply

Your email address will not be published. Required fields are marked *