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
41 changes: 41 additions & 0 deletions 3sum/JeonJe.java

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, Sort
  • 설명: 3sum 문제에서 정렬 후 좌우 포인터를 이동하며 합이 0인 경우를 찾는 전형적인 Two Pointers 패턴이며 중복 제거를 위한 포인터 이동 로직이 포함됩니다. 추가적으로 정렬이 선행되어야 하므로 Sort도 관찰됩니다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 O(n log n) 이후 두 포인터 반복으로 각 x에 대해 선형 탐색으로 전체 복잡도는 O(n^2)입니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.util.*;

// TC: O(n^2)
// SC: O(1)
class Solution {

public List<List<Integer>> threeSum(int[] nums) {

List<List<Integer>> answer = new ArrayList<>();
int n = nums.length;
Arrays.sort(nums);

for (int x = 0; x < n - 2; x++) {
if (x > 0 && nums[x] == nums[x - 1]) continue;

int left = x + 1;
int right = n - 1;

while (left < right) {
if (nums[left] + nums[right] + nums[x] == 0) {
answer.add(Arrays.asList(nums[x], nums[left], nums[right]));

while (left + 1 < right && nums[left] == nums[left + 1]) {
left++;
}
while (left < right - 1 && nums[right] == nums[right - 1]) {
right--;
}
left++;
right--;
} else if (nums[left] + nums[right] + nums[x] < 0) {
left++;
} else {
right--;
}
}
}

return answer;
}
}
31 changes: 31 additions & 0 deletions climbing-stairs/JeonJe.java

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
  • 설명: 피보나치 형태의 문제로 부분 문제를 저장하며 재귀+메모이제이션으로 풀어 Dynamic Programming 패턴에 해당합니다. 해시 맵/셋은 사용되지 않지만 memo 배열로 중복 계산을 제거하는 점에서 DP의 대표적 특징이 드러납니다.

📊 시간/공간 복잡도 분석

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

피드백: 상수 크기의 memo를 재사용해 중복 계산을 막으나 초기화가 매 호출마다 필요하지 않도록 개선 여지 있음.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.util.*;

// TC: O(n)
// SC: O(n)
class Solution {
static int[] memo = new int[46];

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.

문제 조건에 맞춰서 46으로 미리 초기화해두신부분 꼼꼼해서 인상깊습니다!



public int climbStairs(int n) {

if (n == 1) return 1;
if (n == 2) return 2;
memo[1] = 1;
memo[2] = 2;

dfs(n);
return memo[n];
}

private int dfs(int num) {

//이미 계산한적이 있으면
if (memo[num] != 0) {
return memo[num];
}

memo[num] = dfs(num - 1) + dfs(num - 2);
return memo[num];
Comment on lines +20 to +28

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.

DFS로 문제를 푸셨는데, 언제 DFS로 풀고 언제 bottom-up으로 푸시는지 전제님만의 기준이 궁금합니다!


}
}
22 changes: 22 additions & 0 deletions product-of-array-except-self/JeonJe.java

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, Prefix-Drefix, Dynamic Programming
  • 설명: 이 풀이는 각 위치의 왼쪽 곱과 오른쪽 곱을 미리 계산해 곱셈 결과를 구하는 방식으로, O(n) 시간에 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,22 @@
import java.util.*;

// TC: O(n)
// SC: O(1)
class Solution {
public int[] productExceptSelf(int[] nums) {
int n = nums.length;

int[] answer = new int[n];
answer[0] = 1;
for (int i = 1; i < n; i++) {
answer[i] = answer[i - 1] * nums[i - 1];
}

int right = 1;
for (int i = n - 2; i >= 0; i--) {
right = right * nums[i + 1];
answer[i] = answer[i] * right;
}
return answer;
}
}
21 changes: 21 additions & 0 deletions valid-anagram/JeonJe.java

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
  • 설명: 두 문자열의 문자 분포를 비교하기 위해 고정 크기 배열로 카운트를 세는 방법으로 해시 맵/세트의 역할을 대체하며, 각 문자 등장 횟수를 비교해 동등 여부를 판단합니다. 비트 조작은 직접 사용되진 않지만 배열 인덱스로 상수 공간에 매핑하는 패턴과 유사합니다.

📊 시간/공간 복잡도 분석

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

피드백: 알파벳 소문자 범위로 고정된 카운트를 사용해 효율적으로 비교합니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.util.*;

// TC: O(n)
// SC: O(1)
class Solution {
public boolean isAnagram(String s, String t) {
if (s.length() != t.length()) return false;

int[] countS = new int[26];
int[] countT = new int[26];
for (int i = 0; i < s.length(); i++) {
countS[s.charAt(i) - 'a']++;
countT[t.charAt(i) - 'a']++;
}

for (int i = 0; i < 26; i++) {
if (countS[i] != countT[i]) return false;
}
return true;
}
}
19 changes: 19 additions & 0 deletions validate-binary-search-tree/JeonJe.java

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 유효성 검사 문제에서 재귀적으로 범위를 좁혀가며 좌우 자식 노드를 탐색하는 방식은 이진 검색 트리의 성질을 활용하는 패턴이다. 재귀적 탐색(DFS)으로 각 노드에 대해 허용 범위를 추적하고, 범위를 나눠 문제를 분해한다.

📊 시간/공간 복잡도 분석

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

피드백: 부모-자식 간의 흐름을 범위로 추적해 BST 여부를 검증합니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.*;

// TC: O(n)
// SC: O(h)
class Solution {
public boolean isValidBST(TreeNode root) {
return isValid(root, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);

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.

Double 최대, 최솟값 상수를 저렇게 썼군요 배워갑니다!

}

private boolean isValid(TreeNode node, double min, double max) {
if (node == null) {
return true;
}
if (node.val <= min || node.val >= max) {
return false;
}
return isValid(node.left, min, node.val) && isValid(node.right, node.val, max);
}
}
Loading