Notice
Recent Posts
Recent Comments
Today
Total
01-11 05:49
Link
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Partially Committed

[ํ] ๊ธฐ๋Šฅ๊ฐœ๋ฐœ (JAVA) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm || ๋ฌธ์ œํ’€์ด/PS

[ํ] ๊ธฐ๋Šฅ๊ฐœ๋ฐœ (JAVA)

WonderJay 2022. 9. 3. 14:46
728x90
๋ฐ˜์‘ํ˜•
SMALL

https://school.programmers.co.kr/learn/courses/30/lessons/42586?language=java 

 

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”.

programmers.co.kr

import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

class Solution {
    public int[] solution(int[] progresses, int[] speeds) throws IOException {
        ArrayList<Integer> answer = new ArrayList<>();
        ArrayList<Integer> arr = new ArrayList<>();
        Queue<Integer> q = new LinkedList<>();
        int task = 0;

        for (int i = 0; i < progresses.length; i++) {
            task = (int) Math.ceil(((100 - progresses[i]) / (double) speeds[i]));
            q.add(task);
        }

        while (!q.isEmpty()) {
            int cnt = 1;
            int day = q.poll();
            while (!q.isEmpty() && day >= q.peek()) {
                cnt++;
                q.poll();
            }
            answer.add(cnt);
        }

        return answer.stream().mapToInt(Integer::intValue).toArray();
    }
}
728x90
๋ฐ˜์‘ํ˜•
LIST
Comments