Muscardinus
이중우선순위큐 본문
728x90
programmers.co.kr/learn/courses/30/lessons/42628?language=javascript
function solution(operations) {
var answer = [];
let q = [];
let index;
operations.map((operation) => {
if (operation[0] === "I") {
let num = +operation.split(" ")[1];
q.push(num);
} else if (operation === "D -1") {
if (!q.length) return;
index = q.indexOf(Math.min.apply(null, q));
q.splice(index, 1);
} else if (operation === "D 1") {
if (!q.length) return;
index = q.indexOf(Math.max.apply(null, q));
q.splice(index, 1);
}
})
if (!q.length) return [0, 0];
answer = [Math.max.apply(null, q), Math.min.apply(null, q)];
return answer;
}
728x90
Comments