250x250
반응형
Notice
Recent Posts
Recent Comments
Link
N
(프로그래머스 JS)프린터 본문
728x90
반응형
programmers.co.kr/learn/courses/30/lessons/42587?language=javascript
코딩테스트 연습 - 프린터
일반적인 프린터는 인쇄 요청이 들어온 순서대로 인쇄합니다. 그렇기 때문에 중요한 문서가 나중에 인쇄될 수 있습니다. 이런 문제를 보완하기 위해 중요도가 높은 문서를 먼저 인쇄하는 프린
programmers.co.kr
큐를 이용한 풀이.
대기 목록 중 최댓값이 큐의 맨 앞에 있는지 확인하면서,
내가 원하는 작업인지 체크해야 한다.
우선순위에 밀리는 경우 대기 목록의 맨 뒤에 넣으면서 location도 바꿔주면 된다.
function solution(priorities, location) {
let answer = 0;
while(1){
let max = Math.max.apply(null, priorities);
if(location === 0){
if(max === priorities[location]){
answer++;
break;
}
else{
priorities.push(priorities.shift());
location = priorities.length - 1;
}
}
else{
if(max === priorities[0]){
priorities.shift();
answer++;
}
else{
priorities.push(priorities.shift());
}
location--;
}
}
return answer;
}
728x90
반응형
'프로그래머스 알고리즘 > 2단계' 카테고리의 다른 글
(프로그래머스 JS)기능개발 (0) | 2021.03.09 |
---|---|
(프로그래머스 JS)다리를 지나는 트럭 (0) | 2021.03.09 |
(프로그래머스 c++)배달 (0) | 2021.03.04 |
(프로그래머스 c++)게임 맵 최단거리 (0) | 2021.03.04 |
(프로그래머스 c++)이진 변환 반복하기 (0) | 2020.11.23 |