Skip to content
Open
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 combination-sum/j2h30728.ts

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking
  • 설명: 가능한 수들의 조합을 재귀적으로 탐색하며 목표 합계에 도달할 때까지 후보를 추가/제외하는 방식으로 해를 구한다. 중간에 남은 합이 음수면 가지치기를 하고, 현재 선택을 되돌리며 모든 조합을 탐색한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(k * n^k) O(k * n^k)
Space O(k) O(k)

피드백: 백트래킹으로 모든 조합을 탐색하며, 각 재귀에서 남은 합을 감소시키고 현재 경로를 관리합니다.

개선 제안: 현재 구현이 일반적인 해법에 부합합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 시간 복잡도: O(k * n^k) (n: candidates 길이, k: target / min(candidates) 최대 깊이)
* 공간 복잡도: O(k)
*/
function combinationSum(candidates: number[], target: number): number[][] {
const result: number[][] = [];
const current: number[] = [];

function backtracking(index: number, remain: number) {
if (remain === 0) {
result.push([...current]);
return;
}

if (remain < 0) {
return;
}

for (let i = index; i < candidates.length; i++) {
current.push(candidates[i]);
backtracking(i, remain - candidates[i]);
current.pop();
}
}

backtracking(0, target);
return result;
}
24 changes: 24 additions & 0 deletions decode-ways/j2h30728.ts

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 패턴이며, 두 가지 경우를 합산하여 전체 해를 얻는 방식이다. 문자열의 부분 문자열을 상태로 삼아 중복 없이 계산한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(n) O(n)

피드백: 이전 두 상태만 필요하므로 DP 배열을 사용해 풀이가 안정적입니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 시간 복잡도: O(n)
* 공간 복잡도: O(n)
*/
function numDecodings(s: string): number {
const dp = new Array(s.length + 1).fill(0);
dp[0] = 1;
dp[1] = parseInt(s[0]) === 0 ? 0 : 1;

for (let i = 2; i <= s.length; i++) {
dp[i] = 0;

if (parseInt(s[i - 1]) !== 0) {
dp[i] += dp[i - 1];
}
if (
parseInt(s.slice(i - 2, i)) <= 26 &&
parseInt(s.slice(i - 2, i)) >= 10
) {
dp[i] += dp[i - 2];
}
}
return dp[s.length];
}
28 changes: 28 additions & 0 deletions maximum-subarray/j2h30728.ts

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, Greedy
  • 설명: 연속 부분 배열의 합을 최대화하는 문제로, 부분해의 최댓값을 현재까지의 최댓값과 현재 값의 합으로 갱신하는 방식은 DP의 전형적인 형태이며, Kadane 알고리즘의 아이디어로도 설명됩니다. Greedy 성격의 선택도 포함됩니다.

📊 시간/공간 복잡도 분석

ℹ️ 이 파일에는 2가지 풀이가 포함되어 있어 각각 분석합니다.

풀이 1: maxSubArray1 — Time: ✅ O(n) → O(n) / Space: ✅ O(n) → O(n)
유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(n) O(n)

피드백: Kadane 방식과 유사한 DP 접근으로 각 위치의 최댓값을 유지합니다.

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

풀이 2: maxSubArray2 — Time: ✅ O(n) → O(n) / Space: ✅ O(1) → O(1)
유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(1) O(1)

피드백: 가장 일반적인 최적해로, 메모리 사용을 줄인 버전입니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* 시간 복잡도: O(n)
* 공간 복잡도: O(n)
*/
function maxSubArray1(nums: number[]): number {
const dp = new Array(nums.length).fill(0);
dp[0] = nums[0];

for (let i = 1; i < nums.length; i++) {
dp[i] += Math.max(dp[i - 1] + nums[i], nums[i]);
}
return Math.max(...dp);
}

/**
* 시간 복잡도: O(n)
* 공간 복잡도: O(1)
*/
function maxSubArray2(nums: number[]): number {
let max = nums[0];
let current = nums[0];

for (let i = 1; i < nums.length; i++) {
current = Math.max(current + nums[i], nums[i]);
max = Math.max(max, current);
}
return max;
}
13 changes: 13 additions & 0 deletions number-of-1-bits/j2h30728.ts

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, Greedy, Divide and Conquer
  • 설명: 주어진 코드는 입력 n의 이진 자리수를 하나씩 확인해 비트를 세는 방식으로 1의 개수를 구한다. 비트 수를 순차적으로 처리하는 패턴과 간단한 수학적 분할을 이용하는 점에서 비트 조작 및 단순 루프 기반 접근으로 보인다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(number of bits)
Space O(1) O(1)

피드백: 반복을 통해 비트 수를 직접 셉니다. 비트 연산으로도 최적화 가능.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* 시간 복잡도: O(n) (n: 입력값의 비트 수)
* 공간 복잡도: O(1)
*/
function hammingWeight(n: number): number {
let sum = 0;

while (n > 0) {
sum += Math.abs(n % 2);

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.

abs 없이 sum += n % 2; 만 해줘도 될 거 같습니다!

n = Math.floor(n / 2);
}
return (sum += n);
}
19 changes: 19 additions & 0 deletions valid-palindrome/j2h30728.ts

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
  • 설명: 문자열 전처리 후 양 끝에서 같은지 비교하는 방식으로 가운데로 이동하며 비교하는 패턴으로, 두 포인터가 양끝에서 만나는 지점까지 진행합니다. 이때 불필요한 문자 제거와 소문자화 과정이 포함된 뒤 대칭 여부를 확인합니다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
Time O(n) O(n)
Space O(n) O(n)

피드백: 문자 필터링과 문자열 재구성 후 대칭 비교로 해결합니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 시간 복잡도: O(n)
* 공간 복잡도: O(n)
*/
function isPalindrome(s: string): boolean {
let string = "";
for (const ch of s) {
if ((ch >= "a" && ch <= "z") || (ch >= "A" && ch <= "Z")) {
string += ch.toLowerCase();
}
}
Comment on lines +6 to +11

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.

조건이 alphanumeric 인데 알파벳만 처리해서 테스트 통과가 안되네요! 다시 풀어주셔야 할 거 같아요~


for (let i = 0; i < string.length / 2; i++) {
if (string[i] !== string[string.length - i - 1]) {
return false;
}
}
return true;
}
Loading