728x90
반응형
✍ 프로그래머스에서 문제 따옴.


✍
import java.util.*;
import java.util.stream.Collectors;
public class FunctionDev {
public static void main(String[] args) {
int[] progresses = {93, 30, 55};
int[] speeds = {1,30,5};
// int[] progresses = {95, 90, 99, 99, 80, 99};
// int[] speeds = {1, 1, 1, 1, 1, 1};
solution(progresses, speeds);
}
public static int[] solution(int[] progresses, int[] speeds){
// Stack<Integer> stack = new Stack<Integer>();
Queue<Integer> queue = new LinkedList<>();
for (int i = 0 ; i < progresses.length; i ++ ) {
int count = 0;
while (progresses[i] < 100) {
progresses[i] += speeds[i];
count++;
}
queue.add(count);
}
int temp = 0 ;
int count_num = 0;
List<Integer> lists = new ArrayList<>();
int k = queue.peek();
while ( !queue.isEmpty() ) {
temp = queue.poll();
if ( k >= temp ) {
// 동시 배포 할 작업 개수를 늘린다.
count_num++;
} else {
// 배포 했으므로, 작업 개수를 초기화한다.
lists.add(count_num);
count_num = 1;
}
if (queue.isEmpty()) {
lists.add(count_num);
}
if ( k < temp ) {
k = temp;
}
}
int[] answer = new int[lists.size()];
for (int i = 0 ; i < lists.size(); i ++ ) {
answer[i] = lists.get(i);
}
return answer;
}
}
☁ 크게 고민 할 만한 내용은 없었고,
☁ 각 작업의 작업소요일이 며칠인지 체크하는 게 포인트.
320x100
반응형
'ALGORITHM' 카테고리의 다른 글
Big O / 시간복잡도 / Binary Search / Linear Search (0) | 2022.03.20 |
---|---|
백준 / greedy / 5585 / 거스름돈 (0) | 2022.03.14 |
정렬 알고리즘 / 삽입 / 퀵 / 듀얼 피벗 (0) | 2022.03.11 |
해시, 위장 (0) | 2022.02.21 |
해시, 전화번호 목록 (0) | 2022.02.14 |
728x90
반응형
✍ 프로그래머스에서 문제 따옴.


✍
import java.util.*;
import java.util.stream.Collectors;
public class FunctionDev {
public static void main(String[] args) {
int[] progresses = {93, 30, 55};
int[] speeds = {1,30,5};
// int[] progresses = {95, 90, 99, 99, 80, 99};
// int[] speeds = {1, 1, 1, 1, 1, 1};
solution(progresses, speeds);
}
public static int[] solution(int[] progresses, int[] speeds){
// Stack<Integer> stack = new Stack<Integer>();
Queue<Integer> queue = new LinkedList<>();
for (int i = 0 ; i < progresses.length; i ++ ) {
int count = 0;
while (progresses[i] < 100) {
progresses[i] += speeds[i];
count++;
}
queue.add(count);
}
int temp = 0 ;
int count_num = 0;
List<Integer> lists = new ArrayList<>();
int k = queue.peek();
while ( !queue.isEmpty() ) {
temp = queue.poll();
if ( k >= temp ) {
// 동시 배포 할 작업 개수를 늘린다.
count_num++;
} else {
// 배포 했으므로, 작업 개수를 초기화한다.
lists.add(count_num);
count_num = 1;
}
if (queue.isEmpty()) {
lists.add(count_num);
}
if ( k < temp ) {
k = temp;
}
}
int[] answer = new int[lists.size()];
for (int i = 0 ; i < lists.size(); i ++ ) {
answer[i] = lists.get(i);
}
return answer;
}
}
☁ 크게 고민 할 만한 내용은 없었고,
☁ 각 작업의 작업소요일이 며칠인지 체크하는 게 포인트.
320x100
반응형
'ALGORITHM' 카테고리의 다른 글
Big O / 시간복잡도 / Binary Search / Linear Search (0) | 2022.03.20 |
---|---|
백준 / greedy / 5585 / 거스름돈 (0) | 2022.03.14 |
정렬 알고리즘 / 삽입 / 퀵 / 듀얼 피벗 (0) | 2022.03.11 |
해시, 위장 (0) | 2022.02.21 |
해시, 전화번호 목록 (0) | 2022.02.14 |