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
37 changes: 37 additions & 0 deletions 3sum/seueooo.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을 해결합니다. 중복 제거 로직도 함께 사용됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 이후 중복 제거를 통해 필요 연산을 줄이고, 각 i마다 l/h를 이동시켜 전체를 두 포인터로 탐색한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
정렬, 투포인터
정렬 후, 첫 번째 수를 고정하고 나머지 두 수를 투포인터로 탐색
중복되는 경우는 스킵
시간 복잡도: O(n^2)
공간 복잡도: O(n)
* @param {number[]} nums
* @return {number[][]}
*/
var threeSum = function (nums) {
nums.sort((a, b) => a - b);
let n = nums.length;
let answer = [];
for (let i = 0; i < n - 2; i++) {
let l = i + 1;
let h = n - 1;
if (nums[i] > 0) break;
// 중복 제거
if (i > 0 && nums[i] === nums[i - 1]) continue;

while (l < h) {
const sum = nums[i] + nums[l] + nums[h];
if (sum > 0) {
h--;
} else if (sum < 0) {
l++;
} else {
answer.push([nums[i], nums[l], nums[h]]);
while (l < h && nums[l] === nums[l + 1]) l++;
while (l < h && nums[h] === nums[h - 1]) h--;
l++;
h--;
}
}
Comment on lines +14 to +34

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 answer;
};
34 changes: 34 additions & 0 deletions combination-sum/seueooo.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, DFS
  • 설명: 재귀 탐색으로 가능한 조합을 탐색하고 유효한 해를 백트래킹으로 걸러내는 구조입니다. 시작 지점부터 후보를 차례로 시도하고 합이 타깃을 넘으면 재귀를 중단합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(N^T/M)
Space O(T/M)

피드백: 가능한 모든 조합을 중복 없이 탐색하는 DFS 방식이다. 가지치기 조건(sum > target)으로 일부 경우를 절감한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
백트래킹, dfs
시간복잡도 O(N^(T / M))
공간복잡도 O(T / M)

N = candidates.length
T = target
M = candidates 중 최솟값

Comment on lines +6 to +9

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.

요 부분은 코드랑은 관련 없고 시간복잡도 계산에서 T / M의 의미를 설명하려고 둔 주석이에요 !

* @param {number[]} candidates
* @param {number} target
* @return {number[][]}
*/
var combinationSum = function (candidates, target) {
let result = [];

function dfs(start, path, sum) {
if (sum === target) {
result.push([...path]);
return;
}
if (sum > target) return;

for (let i = start; i < candidates.length; i++) {
path.push(candidates[i]);
dfs(i, path, sum + candidates[i]);

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.

start를 넘겨 중복 조합을 막고, 재귀 후 pop()으로 상태를 복구하는 흐름이 잘 읽혔습니다! 현재도 정답이지만 candidates를 먼저 정렬한 뒤 sum + candidates[i] > target일 때 break하면, 뒤의 더 큰 후보를 더 탐색하지 않아도 돼서 가지치기를 조금 더 일찍 할 수 있을 것 같아요.

path.pop();
}
}

dfs(0, [], 0);

return result;
};
25 changes: 25 additions & 0 deletions decode-ways/seueooo.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 접근이다. 1글자 또는 2글자 단위로 경우를 나누어 누적 합을 구하는 전형적인 DP 문제다.

📊 시간/공간 복잡도 분석

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

피드백: 한 자리 수 가능 여부와 두 자리 수 가능 여부를 조합해 상태를 갱신하는 표준 풀이이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
0부터 i번 인덱스 문자열 내에서 해석가능한 조합 개수를 dp에 저장
* @param {string} s
* @return {number}
*/
var numDecodings = function (s) {
if (s[0] === "0") return 0;
let dp = new Array(s.length).fill(0);
dp[0] = 1;
for (let i = 1; i < s.length; i++) {
if (s[i] !== "0") {
dp[i] += dp[i - 1];
}

// 두 자리 수인 경우 (마지막 두덩이를 하나로 생각)
const two = Number(s.slice(i - 1, i + 1));

if (two >= 10 && two <= 26) {
if (i === 1) {
dp[i] += 1;
} else dp[i] += dp[i - 2];
Comment thread
seueooo marked this conversation as resolved.
}
}
return dp[s.length - 1];
};
18 changes: 18 additions & 0 deletions maximum-subarray/seueooo.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, Greedy
  • 설명: 배열을 순회하며 현재 구간의 최댓값을 누적해 이전 상태와 비교하는 방식으로 부분배열의 최대합을 구한다. 피보나치처럼 직전 결과를 이용해 다음 값을 계산하는 DP(또는 관찰 가능한 그리디 형태) 패턴에 속한다.

📊 시간/공간 복잡도 분석

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

피드백: 이전 누적합과 현재 원소를 비교해 최대 구간 합을 갱신한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* 구간 내 최대 합을 dp에 저장
* 시간복잡도 O(n)
* 공간복잡도 O(1)
* @param {number[]} nums
* @return {number}
*/
var maxSubArray = function (nums) {
let prev = nums[0];
let max = nums[0];

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

return max;
};
15 changes: 15 additions & 0 deletions number-of-1-bits/seueooo.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, Bit Manipulation, Greedy, Divide and Conquer, Hash Map / Hash Set
  • 설명: 입력 숫자를 이진수로 다루며, 각 단계에서 n을 2로 나눠 1의 개수를 세는 방식으로 비트를 확인합니다. 비트 단위의 직접적 조작보단 나눗셈으로 차례로 확인하는 패턴은 Bit Manipulation 계열에 속합니다. 추가적으로 간단한 반복으로 해결하는 구조라 Divide and Conquer의 요소가 보일 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 가장 간단한 자리수 개수 세기 방식으로 동작한다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* 정수 n의 이진수 표현에서 1의 개수를 반환
* 시간복잡도 O(log n) - 매 반복마다 n이 절반으로 줄어듦
* 공간복잡도 O(1)
* @param {number} n
* @return {number}
*/
var hammingWeight = function (n) {
let count = 0;
while (n > 0) {
if (n % 2 === 1) count++;
n = Math.floor(n / 2);
}
return count;
Comment on lines +8 to +14

@parkhojeong parkhojeong Jul 10, 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.

사소한 부분이긴 한데 요런 스타일도 한 번 고려해보셔도 좋을 거 같습니다!

  • python에는 n // 2 처럼 깔끔하게 표현이 되는데 js 는 비슷한 연산이 n >> 1 일 거 같네요. 한 번 고려해보셔도 좋을 거 같습니다 :)
  • count 부분은 n % 2 의 결과가 0, 1이어서 count += n % 2로 써볼 수도 있을 거 같습니다!
Suggested change
var hammingWeight = function (n) {
let count = 0;
while (n > 0) {
if (n % 2 === 1) count++;
n = Math.floor(n / 2);
}
return count;
var hammingWeight = function (n) {
let count = 0;
while (n > 0) {
count += n % 2;
n >>= 1;
}
return count;

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.

시프트 연산자를 거의 사용해보지 않아서 잘 몰랐는데 좋은 정보 알아갑니다 :)

};
16 changes: 16 additions & 0 deletions valid-palindrome/seueooo.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Greedy, Two Pointers, Hash Map / Hash Set
  • 설명: 정규식으로 문자열 전처리 후 양 끝에서 동일 여부를 확인하는 방식으로, 두 포인터로 대칭 비교하는 Two Pointers 패턴과, 필요 시 한정된 조건에서 최적 부분을 활용하는 Greedy 성격이 보입니다. 또한 입력 문자열의 문자 제거 및 비교 과정에서 해시 같은 추가 자료구조는 사용하지 않아 핵심은 투 포인터 대칭 비교 입니다.

📊 시간/공간 복잡도 분석

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

피드백: 전처리 문자열 길이에 비례하는 추가 공간과 선형 시간 복잡도를 가진다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* 정규표현식으로 알파벳과 숫자만 남기고 소문자로 변환 후, 양 끝에서부터 비교
* 시간복잡도 O(n)
* 공간복잡도 O(n)
* @param {string} s
* @return {boolean}
*/
var isPalindrome = function (s) {
let newArr = s.replace(/[^a-zA-Z0-9]/g, "").toLowerCase();
for (let i = 0; i < Math.ceil(newArr.length / 2); i++) {
if (newArr[i] !== newArr[newArr.length - 1 - i]) {
return false;
}
}
return true;
};
27 changes: 27 additions & 0 deletions validate-binary-search-tree/seueooo.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, Monotonic Stack, DFS, Inorder Traversal
  • 설명: 중위 순회(Inorder Traversal)로 트리를 방문하며 이전 값과의 대소를 비교해 BST 여부를 확인. 순회 자체는 DFS의 한 형태이고, 순회 중 값이 증가하는지 모니터링하는 Monotonic 특성을 활용한다.

📊 시간/공간 복잡도 분석

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

피드백: 전위/중위 순회에서의 누적 비교로 BST 여부를 판별한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
중위 순회하면서 계속 값이 커지는지 확인
시간복잡도 O(n)
공간복잡도 O(n)
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {boolean}
*/
var isValidBST = function (root) {
let prev = -Infinity;

const inOrder = (node) => {
if (!node) return true;
if (!inOrder(node.left)) return false;
if (node.val <= prev) return false;
prev = node.val;
return inOrder(node.right);
};
return inOrder(root);
Comment on lines +17 to +26

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.

inOrder 방식으로 풀어주셨군요! 전역변수 prev를 사용하고 있는데 순수 함수 형태로 풀어보셔도 좋을 거 같아요!

};
Loading