Hayden's Archive
[알고리즘] 프로그래머스 : 기능개발 본문
알고리즘 문제 출처 : programmers.co.kr/learn/courses/30/lessons/42586
내가 작성한 코드
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int[] answer = {};
Queue<Integer> queue = new LinkedList<Integer>();
List<Integer> list = new ArrayList<>();
for(int i=0; i<progresses.length; i++) {
queue.add(takeDays(progresses[i], speeds[i]));
}
while(!queue.isEmpty()) {
int picked = queue.poll();
int fnCnt = 1;
while(!queue.isEmpty()) {
if(picked >= queue.peek()) {
queue.poll();
fnCnt++;
}else {
break;
}
}
list.add(fnCnt);
}
answer = new int[list.size()];
for(int i=0; i<answer.length; i++) {
answer[i] = list.get(i);
}
return answer;
}
public int takeDays(int progress, int speed) {
int needs = 100 - progress;
if(needs % speed == 0) {
return needs/speed;
}else {
return (needs/speed) + 1;
}
}
}