언젠가는 펼쳐 볼 아카이브
[Programmers] 이중우선순위큐 본문
사용언어 : javascript
lv.3
문제풀이 소요 시간 : 5분 21초
문제 유형 : 힙(Heap)
#문제
#제출코드
function solution(operations) {
let queue = [];
operations.map(operator => {
const [op , num] = operator.split(" ");
if(op === "I"){
queue.push(+num);
queue.sort((a, b) => a-b);
}
if(op === "D" && queue.length > 0){
if(num === "-1"){
queue.shift();
}else {
queue.pop();
}
}
})
return queue.length > 0 ? [queue[queue.length-1], queue[0]] : [0,0];
}
'IT > Programmers' 카테고리의 다른 글
[Programmers] 최고의 집합 (0) | 2024.03.21 |
---|---|
[Programmers] 야근 지수 (0) | 2024.03.20 |
[Programmers] 정수 삼각형 (0) | 2024.03.20 |
[Programmers] 단어 변환 (0) | 2024.03.20 |
[Programmers] 여행경로 (0) | 2024.03.20 |