⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

2026-02-05 문제 풀었어요#27

Open
uyeon0 wants to merge 1 commit intomainfrom
upload
Open

2026-02-05 문제 풀었어요#27
uyeon0 wants to merge 1 commit intomainfrom
upload

Conversation

@uyeon0
Copy link
Collaborator

@uyeon0 uyeon0 commented Feb 5, 2026

User description

오늘도 멋져요 👍✨


PR Type

Enhancement


Description

  • 프로그래머스 42628 이중우선순위큐 문제 해결

  • 최소/최대 힙을 사용한 복잡한 알고리즘 구현

  • 고유 ID를 통한 삭제 추적 메커니즘 개발


@uyeon0 uyeon0 added the programmers Programmers 문제 풀이 label Feb 5, 2026
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

PR Reviewer Guide 🔍

🧪 No relevant tests
⚡ Recommended focus areas for review

알고리즘 복잡성

이중 힙 구현에서 삭제 연산의 시간 복잡도를 개선할 필요가 있습니다. 현재 구현은 O(log n) 삭제 연산 시 추가 순회로 인해 실제 성능이 저하될 수 있습니다.

if (value === "1") {
  // MAX heap에서 삭제
  while (maxHeap.size() > 0) {
    const x = maxHeap.pop();
    if (deleted.has(x.id)) continue;
    else {
      deleted.add(x.id);
      break;
    }
  }
} else if (value === "-1") {
  // MIN heap에서 삭제
  while (minHeap.size() > 0) {
    const x = minHeap.pop();
    if (deleted.has(x.id)) continue;
    else {
      deleted.add(x.id);
      break;
    }
  }
}
메모리 효율성

deleted Set을 사용한 삭제 추적 메커니즘은 메모리 오버헤드를 발생시킬 수 있습니다. 더 효율적인 삭제 추적 방법을 고려해야 합니다.

const deleted = new Set();
for (const operation of operations) {
  const [op, value] = operation.split(" ");
  if (op === "I") {
    const num = Number(value);
    minHeap.push({ id, value: num });
    maxHeap.push({ id, value: num });
    id++;

@github-actions
Copy link

github-actions bot commented Feb 5, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
힙 삭제 로직 중복 제거 및 추상화

삭제 로직이 중복되어 있어 중복 코드를 제거하고 공통 로직을 추출할 수 있습니다. 삭제 연산의 중복 로직을 하나의 메서드로 추상화하여 코드의 가독성과
유지보수성을 개선할 수 있습니다.

Programmers/Level3/42628_이중우선순위큐.js [76-105]

+const deleteFromHeap = (heap, isMax) => {
+  while (heap.size() > 0) {
+    const x = heap.pop();
+    if (!deleted.has(x.id)) {
+      deleted.add(x.id);
+      break;
+    }
+  }
+};
+
 for (const operation of operations) {
   const [op, value] = operation.split(" ");
   if (op === "I") {
     const num = Number(value);
     minHeap.push({ id, value: num });
     maxHeap.push({ id, value: num });
     id++;
   } else if (op === "D") {
-    if (value === "1") {
-      // MAX heap에서 삭제
-      while (maxHeap.size() > 0) {
-        const x = maxHeap.pop();
-        if (deleted.has(x.id)) continue;
-        else {
-          deleted.add(x.id);
-          break;
-        }
-      }
-    } else if (value === "-1") {
-      // MIN heap에서 삭제
-      while (minHeap.size() > 0) {
-        const x = minHeap.pop();
-        if (deleted.has(x.id)) continue;
-        else {
-          deleted.add(x.id);
-          break;
-        }
-      }
-    }
+    value === "1" 
+      ? deleteFromHeap(maxHeap, true) 
+      : deleteFromHeap(minHeap, false);
   }
 }
Suggestion importance[1-10]: 8

__

Why: The suggestion effectively extracts a common deletion logic into a separate function deleteFromHeap, reducing code duplication and improving the overall maintainability of the code. The abstraction makes the code more modular and easier to understand.

Medium
중복 코드 제거 및 결과 반환 로직 개선

현재 popValid 함수는 중복 코드를 포함하고 있습니다. 이 함수를 더 간결하고 효율적으로 리팩토링할 수 있습니다. 또한 최종 결과 반환 로직을
개선하여 코드의 가독성을 높일 수 있습니다.

Programmers/Level3/42628_이중우선순위큐.js [108-123]

 function popValid(heap, deleted) {
   while (heap.size() > 0) {
     const node = heap.pop();
-    if (node === null) return null;
-    if (deleted.has(node.id)) continue;
-    return node;
+    if (node !== null && !deleted.has(node.id)) {
+      return node;
+    }
   }
   return null;
 }
 
 const maxNode = popValid(maxHeap, deleted);
-if (maxNode === null) return [0, 0];
 const minNode = popValid(minHeap, deleted);
-if (minNode === null) return [0, 0];
 
-return [maxNode.value, minNode.value];
+return maxNode && minNode 
+  ? [maxNode.value, minNode.value] 
+  : [0, 0];
Suggestion importance[1-10]: 7

__

Why: The suggestion reduces code duplication in the popValid function and simplifies the result return logic. The improved code is more concise and readable, with a cleaner approach to handling edge cases.

Medium

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

programmers Programmers 문제 풀이

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants