이중우선순위큐

const solution = (operations) => {
  const queue = [];
  operations.forEach((exp) => {
    const [command, number] = exp.split(" ");
    if (command == "I") {
      queue.push(parseInt(number));
      queue.sort((a, b) => b - a);
      return;
    }
    if (command == "D") {
      if (number == "1") {
        queue.shift();
      } else {
        queue.pop();
      }
    }
  });
  if (queue.length == 0) {
    return [0, 0];
  }
  return [queue[0], queue[queue.length - 1]];
};
  • 일단 이중우선순위큐는 구현할 줄도 모르고, 설령 할 줄 안다 치더라도 오류 없이 구현해내려면 시간이 상당히 오래 걸릴 것 같아서 이렇게 풀었다.

0개의 댓글