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
22 changes: 22 additions & 0 deletions coin-change/Yiseull.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 아이디어로, 각 금액 i에 대해 모든 동전을 사용해 dp[i]를 갱신하는 전형적인 동적 계획법 문제의 풀이이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(amount * C)
Space O(amount)

피드백: 금액마다 모든 동전을 고려해 dp[i]를 갱신한다. dp 배열 크기는 amount+1 이고, 외부 루프가 amount 번, 내부가 동전 수(C) 만큼 수행된다.

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

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

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

private int answer = Integer.MAX_VALUE;

public int coinChange(int[] coins, int amount) {
final int IMPOSSIBLE = amount + 1;

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

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

return dp[amount] == IMPOSSIBLE ? -1 : dp[amount];
}
Comment on lines +8 to +21

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.

dp[amount] > amount가 실제로 amount + 1 인지를 비교하는 거고 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.

매직넘버로 인해 풀이 가독성이 더 올라갔네요 감사합니다~!

}
21 changes: 21 additions & 0 deletions find-minimum-in-rotated-sorted-array/Yiseull.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
  • 설명: 배열이 로테이션된 정렬 배열이라는 전제 아래, 중간 값을 기준으로 좌우를 구분해 범위를 절반으로 줄이는 이진 탐색 패턴이 사용됩니다. 시간복잡도 O(log n)로 최솟값을 찾습니다.

📊 시간/공간 복잡도 분석

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

피드백: 양 끝 비교와 중간값 비교로 최솟값 인덱스를 이진 탐색으로 좁혀 간다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Solution {
public int findMin(int[] nums) {
return binarySearch(nums);
}

// 공간복잡도: O(1), 시간복잡도: O(logn)
private int binarySearch(int[] nums) {
int left = 0, right = nums.length - 1;

while (left < right) {
if (nums[left] <= nums[right]) return nums[left];

int mid = (left + right) / 2;

if (nums[right] < nums[mid]) left = mid + 1;
else right = mid;
}

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

피드백: 노드 방문은 한 번씩 이루어지며, 재귀 스택은 트리의 높이 h 만큼 사용된다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {

public int maxDepth(TreeNode root) {
return dfs(root);
}

private int dfs(TreeNode node) {
if (node == null) {
return 0;
}

return 1 + Math.max(dfs(node.left), dfs(node.right));
}
}
31 changes: 31 additions & 0 deletions merge-two-sorted-lists/Yiseull.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, Linked List
  • 설명: 두 개의 정렬된 연결 리스트를 포인터 두 개로 순차적으로 비교해 작은 노드를 연결하는 방식으로 합치는 패턴이다. 리스트의 길이가 n, m일 때 선형 시간으로 동작한다.

📊 시간/공간 복잡도 분석

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

피드백: 두 리스트를 병합하여 비교적으로 선형 시간에 처리한다. 추가 노드 생성 없이 기존 노드를 연결한다.

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Definition for singly-linked list.
* public class ListNode {
* int val;
* ListNode next;
* ListNode() {}
* ListNode(int val) { this.val = val; }
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
* }
*/
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode head = new ListNode(-1);
ListNode current = head;

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

current.next = (list1 != null) ? list1 : list2;

return head.next;
}
}
35 changes: 35 additions & 0 deletions word-search/Yiseull.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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Backtracking, Depth-First Search, Hash Map / Hash Set
  • 설명: 단어를 보드에서 DFS로 탐색하며, 방문한 셀을 임시로 표시하고 되돌려 놓는 방식으로 모든 경로를 탐색한다. 이 풀이의 핵심은 재귀를 이용한 백트래킹으로 가능한 경로를 탐색하는 패턴이다.

📊 시간/공간 복잡도 분석

복잡도
Time O(4^(L) * M * N)
Space O(L)

피드백: 최악의 경우 모든 경로를 탐색하므로 지수적 시간 복잡도가 된다. 중복 방문 방지를 위해 방문 흔적을 남긴다.

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

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

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

private final int[] dx = {-1, 1, 0, 0};
private final int[] dy = {0, 0, -1, 1};

public boolean exist(char[][] board, String word) {
for (int i = 0; i < board.length; i++) {
for (int j = 0; j < board[0].length; j++) {
if (board[i][j] == word.charAt(0) && dfs(board, word, i, j, 1)) {
return true;
}
}
}

return false;
}

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

char tmp = board[x][y];
board[x][y] = '0';

for (int i = 0; i < 4; i++) {
int nextX = x + dx[i], nextY = y + dy[i];
if (0 <= nextX && nextX < board.length && 0 <= nextY && nextY < board[0].length && board[nextX][nextY] == word.charAt(index)) {
if(dfs(board, word, nextX, nextY, index + 1)) return true;
}
}

board[x][y] = tmp;

return false;
}
}
Loading