문제 : https://programmers.co.kr/learn/courses/30/lessons/42586
코딩테스트 연습 - 기능개발
프로그래머스 팀에서는 기능 개선 작업을 수행 중입니다. 각 기능은 진도가 100%일 때 서비스에 반영할 수 있습니다. 또, 각 기능의 개발속도는 모두 다르기 때문에 뒤에 있는 기능이 앞에 있는
programmers.co.kr
문제유형 : 자료구조(큐/스택), 구현
풀이방식 :
큐를 이용해서 구현.
1. 큐에는 각 작업들이 배포가 되는 날짜들을 넣어 주었다
2. 큐를 빼주면서 preValue(이전 값중 최고봉), nowValue를 비교하며 count
3. count 값을 list에 넣어주고 anwer로 옮겨 넣어주었다.
※ 테스트케이스 11번만 통과가 안된이유
- 배포는 하루에 한 번만 할 수 있으며, 하루의 끝에 이루어진다고 가정합니다. 예를 들어 진도율이 95%인 작업의 개발 속도가 하루에 4%라면 배포는 2일 뒤에 이루어집니다.
를 간과해 queue.offer 부분에서 반올림 처리를 안했다. 나는 언제쯤 사람이 될까
소스코드
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
Queue<Integer> queue = new LinkedList<Integer>();
int length = progresses.length;
for(int i=0; i<length; i++) {
queue.offer((int)Math.ceil((double)(100-progresses[i])/speeds[i]));
}
List<Integer> list = new ArrayList<Integer>();
int preValue = queue.poll();
int count = 1;
int nowValue = 0;
while(!queue.isEmpty()){
nowValue = queue.poll();
if(preValue >= nowValue){
count++;
}else {
preValue = nowValue;
list.add(count);
count = 1;
}
}
list.add(count);
int[] answer = new int[list.size()];
for(int i=0; i<list.size(); i++){
answer[i] = list.get(i);
}
return answer;
}
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[JAVA]프로그래머스_땅따먹기 (0) | 2021.08.12 |
---|---|
[JAVA]프로그래머스_게임맵최단거리 (0) | 2021.08.05 |
[JAVA]프로그래머스_올바른 괄호 (0) | 2021.07.30 |
[JAVA]프로그래머스_짝지어 제거하기 (0) | 2021.07.26 |
[JAVA]프로그래머스_스킬트리 (0) | 2021.04.06 |