Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
17 changes: 17 additions & 0 deletions find-minimum-in-rotated-sorted-array/tigermint.kt

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)

피드백: 이진 탐색으로 왼쪽/오른쪽의 중간 비교를 통해 최소값 위치를 좁혀 나간다.

개선 제안: 코드가 간결해 보이나, mid와 right 비교 조건을 명확히 주석으로 구분하면 가독성을 높일 수 있다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
fun findMin(nums: IntArray): Int {
var left = 0
var right = nums.size - 1

while (left < right) {
val mid = (left + right) / 2

when {

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

작성하신 로직의 아이디어에서 중간에 해답인 케이스를 알 수 있는데요. 이 떄는 더 이상 진행할 필요가 없어서 최적화 해보셔도 좋을 거 같습니다.

nums[mid] > nums[right] -> left = mid + 1 // 오른쪽 존재
nums[mid] <= nums[right] -> right = mid // 왼쪽 존재 or 나 자신
}
}

return nums[left]
}
}
30 changes: 30 additions & 0 deletions maximum-depth-of-binary-tree/tigermint.kt

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로 탐색하면서 깊이를 누적하고, 리프에서 최대 깊이를 업데이트하는 구조로 구현되어 있습니다. 트리 순회에 DFS 패턴이 가장 잘 맞습니다.

📊 시간/공간 복잡도 분석

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

피드백: 루트에서 모든 노드를 방문하며, 재귀 스택의 깊이가 트리의 높이(h) 만큼 사용된다.

개선 제안: 재귀 대신 명시적 스택을 사용한 구현으로 스택 깊이 한계 문제를 피할 수 있다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Example:
* var ti = TreeNode(5)
* var v = ti.`val`
* Definition for a binary tree node.
* class TreeNode(var `val`: Int) {
* var left: TreeNode? = null
* var right: TreeNode? = null
* }
*/
class Solution {
fun maxDepth(root: TreeNode?): Int {
if (root == null) return 0

var maxDepth = 0

fun dfs(node: TreeNode, depth: Int) {
//leaf node
if (node.left == null && node.right == null) maxDepth = maxOf(maxDepth, depth)

if (node.left != null) dfs(node.left!!, depth + 1)
if (node.right != null) dfs(node.right!!, depth + 1)
}

dfs(root!!, 1)

return maxDepth
}
Comment thread
tigermint marked this conversation as resolved.

}
33 changes: 33 additions & 0 deletions merge-two-sorted-lists/tigermint.kt

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
  • 설명: 두 정렬 리스트를 병합하기 위해 포인터 두 개(l1, l2)와 하나의 꼬리 포인터를 사용해 순회하며 작은 값을 붙여나가는 패턴으로, 리스트 노드 연결을 직접 수정합니다.

📊 시간/공간 복잡도 분석

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

피드백: 새로운 리스트를 만들어 연결해 나가며, 두 포인터를 이용해 선형 시간에 병합한다.

개선 제안: 리스트 노드 재활용으로 불필요한 새 노드 생성 없이 구현 가능하면 공간을 더 낮출 수 있다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Example:
* var li = ListNode(5)
* var v = li.`val`
* Definition for singly-linked list.
* class ListNode(var `val`: Int) {
* var next: ListNode? = null
* }
*/
class Solution {
fun mergeTwoLists(list1: ListNode?, list2: ListNode?): ListNode? {
val head = ListNode(0)
var tail = head
var l1 = list1
var l2 = list2

while (l1 != null && l2 != null) {
if (l1.`val` <= l2.`val`) {
tail.next = l1
l1 = l1.next
} else {
tail.next = l2
l2 = l2.next
}

tail = tail.next!!
}

tail.next = l1 ?: l2

return head!!.next
Comment thread
tigermint marked this conversation as resolved.
Outdated
}
}
53 changes: 53 additions & 0 deletions word-search/tigermint.kt

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
  • 설명: 단어의 경로를 탐색하며 방문 여부를 관리하고 가능한 모든 경로를 재귀적으로 탐색하는 백트래킹 기법이 핵심이며, DFS로 인접 칸을 따라 탐색하는 구조를 가집니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(4^L)
Space O(rows * cols)

피드백: 한 글자씩 네 방향으로 DFS를 확장하고 방문 여부를 관리하여 모든 시작 위치에서 탐색한다.

개선 제안: 백트래킹 prune 조건을 강화하거나, 보드 크기가 커질 때는 DP/메모이제이션으로 중복 탐색을 줄일 수 있다.

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

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

private val dx = intArrayOf(-1, 1, 0, 0)
private val dy = intArrayOf(0, 0, -1, 1)

fun exist(board: Array<CharArray>, word: String): Boolean {
val rows = board.size
val cols = board[0].size
val visited = Array(rows) { BooleanArray(cols) }

Comment on lines +9 to +10

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.

board를 활용해 방문한 셀은 마킹해놓는 식으로 하면 visited 선언 없이도 가능하니 이렇게 풀어보시는 것도 추천드립니다.

val starts = mutableListOf<Pair<Int, Int>>()
for (i in 0 until rows) {
for (j in 0 until cols) {
if (board[i][j] == word[0]) starts.add(i to j)
}
}

if (word.length == 1) return starts.isNotEmpty()

Comment on lines +18 to +19

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% 정도 나오는데요. board, word 인풋을 가지고 미리 리턴할 수 있는 케이스도 고려해서 최적화 해보시면 좋을 거 같습니다.

var flag = false

fun dfs(start: Pair<Int, Int>, index: Int) {
if (flag) return
if (index == word.length - 1) {
flag = true
return
Comment on lines +20 to +26

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

전역변수 flag 대신 dfs 함수의 반환 값을 boolean으로 활용해보셔도 좋을 거 같습니다.

}

for (i in 0 until 4) {
val nx = start.first + dx[i]
val ny = start.second + dy[i]

if (nx < 0 || nx >= rows) continue
if (ny < 0 || ny >= cols) continue
if (visited[nx][ny]) continue
if (word[index + 1] != board[nx][ny]) continue

visited[nx][ny] = true
dfs(Pair(nx, ny), index + 1)
visited[nx][ny] = false
}
}

for (start in starts) {
visited[start.first][start.second] = true
dfs(start, 0)
visited[start.first][start.second] = false
if (flag) return true
}

return false
}
}
Loading