Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions missing-number/reeseo3o.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Math
  • 설명: 이 코드는 가우스 공식을 이용하여 연속된 수의 합을 계산하고, 주어진 배열의 합과 비교하여 빠르게 누락된 숫자를 찾는다. 수학적 공식 활용이 핵심이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 배열의 길이와 합을 계산하는 간단한 방법으로 시간 복잡도는 선형, 공간은 상수입니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Time Complexity: O(n)
// Space Complexity: O(1)

const missingNumber = (nums) => {
const n = nums.length;
const total = (n * (n + 1)) / 2; // 가우스 공식
const sum = nums.reduce((acc, cur) => acc + cur, 0);
return total - sum;
};
42 changes: 42 additions & 0 deletions reorder-list/reeseo3o.js
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Fast & Slow Pointers, Reverse Linked List, Merge Lists
  • 설명: 이 코드는 빠른-느린 포인터로 리스트의 중간을 찾고, 뒤를 뒤집은 후 두 리스트를 교차 병합하는 방식으로 문제를 해결합니다. 주로 연결 리스트의 특정 패턴을 활용하는 알고리즘입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(1)

피드백: 리스트를 한 번 순회하며 중간 찾기, 뒤집기, 병합하는 과정이 모두 선형이므로 시간 복잡도는 O(n), 추가 공간은 상수입니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Time Complexity: O(n)
// Space Complexity: O(1)

const reorderList = (head) => {
if (!head || !head.next || !head.next.next) return;

// 1. 가운데 찾기 (slow는 앞쪽 리스트의 끝)
let slow = head;
let fast = head;
while (fast && fast.next) {
slow = slow.next;
fast = fast.next.next;
}

// 2. 뒷부분 뒤집기 (slow.next ~ 끝)
let prev = null;
let curr = slow.next;
slow.next = null; // 앞부분과 뒷부분 분리

while (curr) {
const next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
// prev: 뒤집힌 두 번째 리스트의 head

// 3. 교차 머지 (head: 첫 번째, prev: 두 번째)
let first = head;
let second = prev;

while (second) {
const nextFirst = first.next;
const nextSecond = second.next;

first.next = second;
second.next = nextFirst;

first = nextFirst;
second = nextSecond;
}
};
Loading