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
24 changes: 24 additions & 0 deletions find-minimum-in-rotated-sorted-array/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
  • 설명: 배열이 회전된 경우 최소값을 찾기 위해 중간값 vs 끝값을 비교해 탐색 범위를 반으로 줄이는 이분 탐색 패턴이다. 로직은 정렬 여부를 판단해 좌우 어느 쪽 부분에 최소값이 있는지 판단하고 구간을 축소한다.

📊 시간/공간 복잡도 분석

유저 분석 실제 분석 결과
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,24 @@
import java.util.*;

// TC: O(log n)
// SC: O(1)
class Solution {
public int findMin(int[] nums) {

int lowIndex = 0;
int highIndex = nums.length - 1;

while(lowIndex < highIndex) {
int midIndex = (lowIndex + highIndex) / 2;

//오른 부분이 정렬 되지 않음 = 왼쪽 부분은 정렬됨
if(nums[midIndex] > nums[highIndex]) {
lowIndex = midIndex + 1;
} else {
//오른쪽 부분이 정렬 됨 = 왼쪽 부분을 봐야함
highIndex = midIndex;
}
}
return nums[lowIndex];
}
}
15 changes: 15 additions & 0 deletions maximum-depth-of-binary-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.

🏷️ 알고리즘 패턴 분석

  • 패턴: DFS, Divide and Conquer
  • 설명: 트리의 각 노드를 방문하며 좌우 자식의 깊이를 재귀로 합쳐 최대 깊이를 구하는 방식으로, 깊이 우선 탐색(DFS)과 재귀 분할로 해결하는 패턴에 해당합니다.

📊 시간/공간 복잡도 분석

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

피드백: 깊이 우선 탐색으로 모든 노드를 한 번씩 방문하여 깊이를 누적합니다.

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

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

// TC: O(n)
// SC: O(h)
class Solution {
public int maxDepth(TreeNode root) {
return calMaxDepth(root);
}

// 현재까지 최대 깊이는 Math.max(왼쪽 서브노드 최대 깊이 , 오른쪽 서브노드 최대깊이) + 1
private int calMaxDepth(TreeNode node) {
if (node == null) return 0;
return Math.max(calMaxDepth(node.left), calMaxDepth(node.right)) + 1;
}
}
31 changes: 31 additions & 0 deletions merge-two-sorted-lists/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, Merge
  • 설명: 리스트를 순회하며 두 포인터(list1, list2)를 비교해 더 작은 값을 차례로 연결하는 방식으로 정렬된 두 연결리스트를 합친다. 빈 리스트를 가리키는 더미 노드를 사용해 간결하게 연결한다.

📊 시간/공간 복잡도 분석

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

피드백: 새 노드를 매번 생성하는 대신 기존 노드를 연결해도 공간 복잡도가 더 좋아질 수 있습니다.

개선 제안: 고려해볼 만한 대안: 기존 노드를 재활용하여 불필요한 객체 생성 제거.

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

// TC: O(n+m)
// SC: O(n+m)
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
ListNode dummy = new ListNode(0);
ListNode tail = dummy;

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

if (list1 != null) {
tail.next = list1;
}

if (list2 != null) {
tail.next = list2;
}

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

🏷️ 알고리즘 패턴 분석

  • 패턴: Depth-First Search, Backtracking
  • 설명: 보드에서 인접한 칸을 탐색하며 단어의 각 글자를 매칭하기 위해 DFS로 탐색하고, 방문 여부를 기록하며 조건에 맞지 않으면 되돌아가므로 Backtracking의 전형적 구현이다.

📊 시간/공간 복잡도 분석

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

피드백: 브루트포스 DFS는 최악의 경우 지수 시간으로 증가할 수 있으나 일반적으로 백트래킹으로 최적화됩니다.

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

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

// TC: O(m * n * 4^L)
// SC: O(m * n)
class Solution {

private char[][] board;
private int m, n;
private boolean[][] visited;
private char[] word;
private static final int[] dx = {-1, 1, 0, 0};
private static final int[] dy = {0, 0, -1, 1};


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

for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (dfs(i, j, 0)) {
return true;
}
}
}
return false;
}

private boolean dfs(int x, int y, int wordIndex) {
if (board[x][y] != word[wordIndex] || visited[x][y]) {
return false;
}
if (wordIndex == word.length - 1) {
return true;
}

visited[x][y] = 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[wordIndex + 1] && !visited[nx][ny]) {
if (dfs(nx, ny, wordIndex + 1)) {
return true;
}
}
}
visited[x][y] = false;
return false;
}
}
Loading