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
12 changes: 12 additions & 0 deletions combination-sum/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming, Backtracking
  • 설명: 코드가 합 후보군으로 목표 합계를 만드는 모든 조합을 DP 테이블에 누적하여 저장합니다. 각 후보를 사용해 부분합을 확장하는 방식은 DP와 조합 구성의 아이디어를 모두 활용합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * t)
Space O(t * m)

피드백: 동적 계획법으로 모든 합에 대한 조합을 저장하지만, 각 합에 여러 조합을 저장하므로 공간이 크게 증가할 수 있다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function combinationSum(candidates, target) {
const dp = Array.from({ length: target + 1 }, () => []);
dp[0] = [[]];
for (let i = 0; i < candidates.length; i++) {
for (let j = candidates[i]; j <= target; j++) {
dp[j].push(
...dp[j - candidates[i]].map((item) => [...item, candidates[i]]),
);
}
}
return dp[target];
}
16 changes: 16 additions & 0 deletions decode-ways/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 문자열을 부분 문제로 나누고 각 위치까지의 최적 해를 저장하는 계단식 DP 접근으로, 이전 상태를 이용해 현재 상태를 갱신합니다. 0-1 문자 해독 규칙과 두 자리 해독 규칙을 합쳐 DP 배열을 채웁니다.

📊 시간/공간 복잡도 분석

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

피드백: 두 자리 숫자 해석 가능 여부를 누적하여 해석 경우의 수를 세는 전형적인 DP 풀이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function numDecodings(s) {
const dp = Array.from({ length: s.length + 1 }, () => 0);
dp[0] = 1;
dp[1] = s[0] === '0' ? 0 : 1;
for (let i = 2; i <= s.length; i++) {
if (s[i - 1] !== '0') {
dp[i] += dp[i - 1];
}

const twoDigits = Number(s.slice(i - 2, i));
if (twoDigits >= 10 && twoDigits <= 26) {
dp[i] += dp[i - 2];
}
}
return dp[s.length];
}
9 changes: 9 additions & 0 deletions maximum-subarray/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Dynamic Programming
  • 설명: 연속 부분배열의 최대 합을 구하는 문제로, 현재 위치까지의 최댓값과 전체 최댓값을 갱신하는 방식은 다이나믹 프로그래밍의 대표적인 Kadane 알고리즘 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

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

피드백: 현재 배열을 한 번 순회하며 최댓값을 갱신한다는 점에서 시간은 선형이고 공간도 상수이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function maxSubArray(nums) {
let max = nums[0];
let current = nums[0];
for (let i = 1; i < nums.length; i++) {
current = Math.max(nums[i], current + nums[i]);
max = Math.max(max, current);
}
return max;
}
6 changes: 6 additions & 0 deletions number-of-1-bits/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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation
  • 설명: 입력 상수를 이진 문자열로 변환한 뒤 '1'의 개수를 세는 방식으로 비트를 직접 다루는 패턴이며, 비트 연산의 기본적 개념에 기반합니다.

📊 시간/공간 복잡도 분석

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

피드백: 문자열 변환 및 배열 조작으로 간단하지만, 비트 연산으로 더 나은 상수 계수를 얻을 수 있다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function hammingWeight(n) {
return n
.toString(2)
.split('')
.filter((v) => v === '1').length;
}
4 changes: 4 additions & 0 deletions valid-palindrome/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, Hash Map / Hash Set, Greedy, Dynamic Programming, Binary Search, Monotonic Stack, Heap / Priority Queue, BFS, DFS, Backtracking, Divide and Conquer, Union Find, Trie, Bit Manipulation
  • 설명: 주어진 코드는 문자열 전처리 후 역순 비교로 회문 여부를 판단한다. 전체 문자열 비교와 역순 재조합 비교를 통해 결과를 얻으므로 단순한 대칭 비교 흐름이 핵심이다.

📊 시간/공간 복잡도 분석

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

피드백: 전처리와 대칭 비교를 통해 한 번의 문자열 순회로 해결한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function isPalindrome(s) {
const letters = s.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();

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.

오 정규식 쓸 생각을 못했었는데 덕분에 깨닫고 갑니다!

return letters === letters.split('').reverse().join('');
}
Loading