Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 28 additions & 0 deletions 3sum/jthw1005.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Sorting
  • 설명: 3Sum은 정렬 후 두 포인터(left, right)로 합을 탐색하는 전형적인 Two Pointers 패턴을 사용한다. 중복 제거를 위한 스킵 로직도 포함되어 있다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 뒤 i 중심으로 좌우 포인터를 이동하며 합이 0인 경우를 수집하고 중복을 건너뛴다.

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

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

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.

저랑 같은 로직으로 작성하셨네요. 잘 봤습니다.
주석으로 공간/시간 복잡도 적어주시면 더 좋을 것 같습니다!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

오 잘 생각 안 하고 풀고 있었는데, 다음부턴 주석에 남겨보겠습니다! 👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function threeSum(nums) {
const result = [];
nums.sort((a, b) => a - b);

for (let i = 0; i < nums.length - 2; i++) {
if (i > 0 && nums[i] === nums[i - 1]) continue;

let left = i + 1;
let right = nums.length - 1;

while (left < right) {
const sum = nums[i] + nums[left] + nums[right];
if (sum === 0) {
result.push([nums[i], nums[left], nums[right]]);
left++;
right--;

while (left < right && nums[left] === nums[left - 1]) left++;
while (left < right && nums[right] === nums[right + 1]) right--;
} else if (sum < 0) {
left++;
} else {
right--;
}
}
}
return result;
}
13 changes: 13 additions & 0 deletions climbing-stairs/jthw1005.js

@okyungjin okyungjin Jul 4, 2026

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.

재귀라서 n이 조금 더 커지면 호출 스택이 많이 쌓일 것 같습니다. 논 재귀로 작성해보시면 좋을 것 같아요!

생각해보니 메모이제이션 재귀라서 아주 비효율적이진 않네요. n이 작아서 지금 풀이로도 충분한 것 같아요.
잘 봤습니다 👍

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Hash Map / Hash Set
  • 설명: 호출 간격을 줄이고 중복 계산을 저장하는 메모이제이션으로 피보나치형 문제를 해결하는 DP 패턴과, memo 객체를 활용한 저장소를 이용한 Hash Map 기법이 함께 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 하나의 하위 문제만 재계산하지 않도록 캐시를 사용했다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function climbStairs(n) {
const memo = {};

function dp(k) {
if (k === 1) return 1;
if (k === 2) return 2;
if (memo[k]) return memo[k];
memo[k] = dp(k - 1) + dp(k - 2);
return memo[k];
}

return dp(n);
}
18 changes: 18 additions & 0 deletions product-of-array-except-self/jthw1005.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Two Pointers, Dynamic Programming, Hash Map / Hash Set
  • 설명: 두 배열 순회를 이용해 각 위치의 곱을 좌우 두 포인터 방식으로 누적 곱흔적을 계산한다. 추가 저장 배열을 사용해 부분 문제를 구성하는 DP 성격이 있고, 두 방향의 누적 곱을 곱해 결과를 구하는 패턴이다.

📊 시간/공간 복잡도 분석

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

피드백: 추가 배열을 사용해 좌우 누적곱을 분리 계산했다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
function productExceptSelf(nums) {
const result = [];
let product = 1;

for (let i = 0; i < nums.length; i++) {
result[i] = product;
product *= nums[i];
}

product = 1;
for (let i = nums.length - 1; i >= 0; i--) {
result[i] *= product;
product *= nums[i];
}
return result;
}

console.log(productExceptSelf([1, 2, 3, 4]));
14 changes: 14 additions & 0 deletions valid-anagram/jthw1005.js

@okyungjin okyungjin Jul 4, 2026

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.

Follow up: What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

팔로업에 소문자 알파벳 외 문자열에 대해서도 처리할 수 있는 로직을 고민해보라고 적혀있습니다!
확장된 코드로 작성해보면 좋을 것 같습니다.


저도 알파벳 소문자만 한정해서 최적화하는 로직으로 작성해봐야겠네요 👍

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.

저는 함수 시작부에 길이 비교를 통해 성능을 조금 최적화해줬습니다.

if (s.length !== t.length) {
   return false;
}


for가 2번 반복되는데, for문을 하나로 합치는 방법도 있을 것 같습니다!

for (let i = 0; i < s.length; i++) {
    data[s.charCodeAt(i) - a_ascii]++;
    data[t.charCodeAt(i) - a_ascii]--;
}

재밌는 풀이 잘 봤습니다 ㅎㅎ!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

소문자 알파벳이 아닌 조건이 추가되니까 더 생각할거리가 생기네요,, 감사합니다!

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Bit Manipulation
  • 설명: 두 문자열의 각 문자 등장 횟수를 비교하기 위해 고정 크기 배열을 사용하여 카운팅하는 방식을 채택했습니다. 해시 맵 없이 배열 인덱스로 차이를 누적하고 마지막에 0 여부로 판단합니다.

📊 시간/공간 복잡도 분석

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

피드백: 알파벳 소문자만 다루는 가정하에 상수 공간으로 해결했다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const isAnagram = (s, t) => {
const data = new Array(26).fill(0);
const a_ascii = 'a'.charCodeAt();

for (const char of s) {
data[char.charCodeAt() - a_ascii]++;
}

for (const char of t) {
data[char.charCodeAt() - a_ascii]--;
}

return !data.some((el) => el !== 0);
};
10 changes: 10 additions & 0 deletions validate-binary-search-tree/jthw1005.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Depth-First Search, Divide and Conquer, Hash Map / Hash Set
  • 설명: BST 유효성 검사 문제로, 트리를 재귀적으로 좌우 자식에 대해 범위를 좁혀가며 확인한다. 각 노드의 값이 허용 구간 안에 있는지 검사하고, 재귀적으로 왼쪽은 작고 오른쪽은 크도록 분할해 풀이한다.

📊 시간/공간 복잡도 분석

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

피드백: 각 노드 방문 시 유효한 최소/최대 값을 넘겨 검증한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function isValidBST(root) {
function helper(node, min, max) {
if (!node) return true;
if (node.val <= min || node.val >= max) return false;
return (
helper(node.left, min, node.val) && helper(node.right, node.val, max)
);
}
return helper(root, -Infinity, Infinity);
}
Loading