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
20 changes: 20 additions & 0 deletions coin-change/jaekwang97.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
  • 설명: 코인 교환 문제에서 금액을 작은 부분 문제로 나누어 최적해를 구하는 DP 풀이입니다. 각 금액에 대해 가능한 동전들로 최소 개수를 업데이트하는 전형적인 동적계획 패턴입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(amount * len(coins))
Space O(amount)

피드백: 동전 종류를 모두 순회하며 각 합에 대해 최솟값을 갱신한다. dp 배열 크기는 amount+1 이므로 필요 공간은 선형이다.

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

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

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

class Solution {
public int coinChange(int[] coins, int amount) {
int[] dp = new int[amount + 1];

Arrays.fill(dp, amount + 1);
dp[0] = 0;

for (int i = 1; i <= amount; i++) {
for (int coin : coins) {
if (i - coin >= 0) {
dp[i] = Math.min(dp[i], dp[i - coin] + 1);
}
}
}

return dp[amount] == amount + 1 ? -1 : dp[amount];
Comment on lines +5 to +18

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.

amount + 1 이 매직넘버라 선언해서 사용하시면 좋을 거 같습니다.

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.

감사합니다. 상수 처리하면 가독성이 더 좋아질 것 같네요!

}
}
18 changes: 18 additions & 0 deletions find-minimum-in-rotated-sorted-array/jaekwang97.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
  • 설명: 회전된 정렬 배열에서 최소값을 이분탐색으로 찾는 패턴으로, 중간값과 양 끝값의 비교를 통해 탐색 구간을 절반으로 축소합니다.

📊 시간/공간 복잡도 분석

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

피드백: 왼쪽/오른쪽 포인터를 이용한 이진 검색으로 최솟값의 위치를 좁혀 간다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public int findMin(int[] nums) {
int left = 0;
int right = nums.length - 1;

while (left < right) {
int mid = left + (right - left) / 2;

if (nums[mid] > nums[right]) {
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.

탐색 중간에 답인 경우 리턴이 가능해서 최적화 해보시면 좋을 거 같습니다.

left = mid + 1;
} else {
right = mid;
}
}

return nums[left];
}
}
25 changes: 25 additions & 0 deletions maximum-depth-of-binary-tree/jaekwang97.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Binary Search
  • 설명: 트리의 깊이를 탐색하며 각 노드의 깊이를 추적하는 DFS 구현으로 깊이 우선 탐색 패턴에 해당합니다. 이 문제는 이진 트리의 최대 깊이를 재귀적으로 구합니다.

📊 시간/공간 복잡도 분석

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

피드백: 전역 max 변수를 사용해 현재 깊이를 추적하며 재귀적으로 자식 노드를 탐색한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class Solution {
private int max;

public int maxDepth(TreeNode root) {
if (root == null) {
return 0;
}

max = 0;
dfs(root, 1);

return max;
}

private void dfs(TreeNode node, int depth) {
if (node == null) {
return;
}

max = Math.max(max, depth);

dfs(node.left, depth + 1);
dfs(node.right, depth + 1);
Comment on lines +2 to +23

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 리턴 값을 사용해보셔도 좋을 거 같습니다.

}
}
32 changes: 32 additions & 0 deletions merge-two-sorted-lists/jaekwang97.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, Merge sort related / Divide and Conquer
  • 설명: 두 정렬된 연결리스트를 순차 탐색하며 더 작은 값을 차례로 연결하는 방식으로, 두 포인터를 이용해 합치는 흐름이 핵심이다. 리스트를 순회하며 새로운 리스트를 만들어 결과를 구성한다.

📊 시간/공간 복잡도 분석

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

피드백: 새로운 노드를 만들어 두 리스트를 병합한다. 최종 길이는 합의 길이이다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode dummy = new ListNode();
ListNode tail = dummy;

while (list1 != null && list2 != null) {
if (list1.val <= list2.val) {
tail.next = new ListNode(list1.val);
list1 = list1.next;
} else {
tail.next = new ListNode(list2.val);
list2 = list2.next;
}

tail = tail.next;
}

while (list1 != null) {
tail.next = new ListNode(list1.val);
tail = tail.next;
list1 = list1.next;
}

while (list2 != null) {
tail.next = new ListNode(list2.val);
tail = tail.next;
list2 = list2.next;
Comment on lines +7 to +27

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.

ListNode 를 새로 만들지 않고 기존 노드만을 이용해서 풀어보셔도 좋을 거 같습니다.

}

return dummy.next;
}
}
55 changes: 55 additions & 0 deletions word-search/jaekwang97.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Backtracking
  • 설명: 단어를 한 칸씩 탐색하며 연결 경로를 재귀적으로 따라가고, 방문한 칸은 임시로 표시해 되돌려놓는 방식으로 모든 경로를 탐색합니다. 이는 DFS와 백트래킹 패턴의 전형적인 예입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n * m * 4^L)
Space O(n * m)

피드백: 모든 시작 위치에서 DFS를 수행하고, 방문 표식을 이용해 중복 방문을 방지한다.

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

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

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.

요거 돌려보니 runtime 50% 정도 나와서 최적화 좀 더 해보셔도 좋을 거 같습니다.

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.

앞으로 풀이할 때 Beats도 같이 봐아겠네요. 백분위였군요👍

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
class Solution {

static int[] dx = {0, 1, 0, -1};
static int[] dy = {1, 0, -1, 0};
static int n, m;

public boolean exist(char[][] board, String word) {
m = board[0].length;
n = board.length;

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (board[i][j] != word.charAt(0)) continue;

char cur = board[i][j];
board[i][j] = '#';
boolean flag = dfs(board, word, 1, i, j);
board[i][j] = cur;

if (flag) return true;
}
}

return false;
}

private static boolean dfs(
char[][] board,
String word,
int idx,
int x,
int y
) {
if (idx == word.length()) return true;

for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];

if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
if (board[nx][ny] != word.charAt(idx)) continue;

char cur = board[nx][ny];
board[nx][ny] = '#';

boolean flag = dfs(board, word, idx + 1, nx, ny);

board[nx][ny] = cur;

if (flag) return true;
}

return false;
}
}
Loading