From b819cdd0441d986c8f5ce79fcc5ef94b68ff1ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Tue, 2 Sep 2025 10:50:14 +0900 Subject: [PATCH 1/5] Add longest substring without repeating characters solution --- .../hyunjung-choi.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 longest-substring-without-repeating-characters/hyunjung-choi.kt diff --git a/longest-substring-without-repeating-characters/hyunjung-choi.kt b/longest-substring-without-repeating-characters/hyunjung-choi.kt new file mode 100644 index 000000000..f4c974421 --- /dev/null +++ b/longest-substring-without-repeating-characters/hyunjung-choi.kt @@ -0,0 +1,24 @@ +/** + * 시간복잡도: O(n) + * 공간복잡도: O(min(m,n)) - m은 문자셋 크기 + */ + +class Solution { + fun lengthOfLongestSubstring(s: String): Int { + val seen = mutableSetOf() + var left = 0 + var maxLength = 0 + + for (right in s.indices) { + while (s[right] in seen) { + seen.remove(s[left]) + left++ + } + + seen.add(s[right]) + maxLength = maxOf(maxLength, right - left + 1) + } + + return maxLength + } +} From 6077f9f437ecc131a3338f3327fa3a45da546e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Tue, 2 Sep 2025 10:52:47 +0900 Subject: [PATCH 2/5] Add reverse linked list solution --- reverse-linked-list/hyunjung-choi.kt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 reverse-linked-list/hyunjung-choi.kt diff --git a/reverse-linked-list/hyunjung-choi.kt b/reverse-linked-list/hyunjung-choi.kt new file mode 100644 index 000000000..e020696da --- /dev/null +++ b/reverse-linked-list/hyunjung-choi.kt @@ -0,0 +1,25 @@ +/** + * 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 reverseList(head: ListNode?): ListNode? { + var prev: ListNode? = null + var current = head + + while (current != null) { + val next = current.next + current.next = prev + prev = current + current = next + } + + return prev + } +} From c6aa5379841e921a827c18fc05a5a8a710c7a24a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Wed, 3 Sep 2025 16:56:28 +0900 Subject: [PATCH 3/5] Add number of islands solution --- number-of-islands/hyunjung-choi.kt | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 number-of-islands/hyunjung-choi.kt diff --git a/number-of-islands/hyunjung-choi.kt b/number-of-islands/hyunjung-choi.kt new file mode 100644 index 000000000..c38f00e2b --- /dev/null +++ b/number-of-islands/hyunjung-choi.kt @@ -0,0 +1,38 @@ +/** + * 시간복잡도: O(M × N) + * 공간복잡도: O(M × N) + */ + +class Solution { + fun numIslands(grid: Array): Int { + if (grid.isEmpty() || grid[0].isEmpty()) return 0 + + val row = grid.size + val column = grid[0].size + var isIslandCount = 0 + + for (i in 0 until row) { + for (j in 0 until column) { + if (grid[i][j] == '1') { + isIslandCount++ + dfs(grid, i, j, row, column) + } + } + } + + return isIslandCount + } + + private fun dfs(grid: Array, i: Int, j: Int, row: Int, column: Int) { + if (i < 0 || i >= row || j < 0 || j >= column || grid[i][j] != '1') { + return + } + + grid[i][j] = '0' + + dfs(grid, i - 1, j, row, column) + dfs(grid, i + 1, j, row, column) + dfs(grid, i, j - 1, row, column) + dfs(grid, i, j + 1, row, column) + } +} From 06aa8e3526d69b4de8bcef7bdbedff063129b70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Thu, 4 Sep 2025 10:53:02 +0900 Subject: [PATCH 4/5] Add unique paths solution --- unique-paths/hyunjung-choi.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 unique-paths/hyunjung-choi.kt diff --git a/unique-paths/hyunjung-choi.kt b/unique-paths/hyunjung-choi.kt new file mode 100644 index 000000000..183e7379f --- /dev/null +++ b/unique-paths/hyunjung-choi.kt @@ -0,0 +1,18 @@ +/** + * 시간 복잡도: O(m * n) + * 공간 복잡도: O(n) + */ + +class Solution { + fun uniquePaths(m: Int, n: Int): Int { + val dp = IntArray(n) { 1 } + + for (i in 1 until m) { + for (j in 1 until n) { + dp[j] += dp[j - 1] + } + } + + return dp[n - 1] + } +} From 3313e13c44e42f5ba329ee10f567eb81c905dde5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=ED=98=84=EC=A0=95?= Date: Fri, 5 Sep 2025 23:00:14 +0900 Subject: [PATCH 5/5] Add set matrix zeroes solution --- set-matrix-zeroes/hyunjung-choi.kt | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 set-matrix-zeroes/hyunjung-choi.kt diff --git a/set-matrix-zeroes/hyunjung-choi.kt b/set-matrix-zeroes/hyunjung-choi.kt new file mode 100644 index 000000000..69d6fc2df --- /dev/null +++ b/set-matrix-zeroes/hyunjung-choi.kt @@ -0,0 +1,57 @@ +/** + * 시간복잡도: O(m × n) + * 공간복잡도: O(1) + */ + +class Solution { + fun setZeroes(matrix: Array): Unit { + val m = matrix.size + val n = matrix[0].size + + var firstRowHasZero = false + var firstColumnHasZero = false + + for (j in 0 until n) { + if (matrix[0][j] == 0) { + firstRowHasZero = true + break + } + } + + for (i in 0 until m) { + if (matrix[i][0] == 0) { + firstColumnHasZero = true + break + } + } + + for (i in 1 until m) { + for (j in 1 until n) { + if (matrix[i][j] == 0) { + matrix[i][0] = 0 + matrix[0][j] = 0 + } + } + } + + for (i in 1 until m) { + for (j in 1 until n) { + if (matrix[i][0] == 0 || matrix[0][j] == 0) { + matrix[i][j] = 0 + } + } + } + + for (j in 0 until n) { + if (firstRowHasZero) { + matrix[0][j] = 0 + } + } + + for (i in 0 until m) { + if (firstColumnHasZero) { + matrix[i][0] = 0 + } + } + } +}