From c2e782b8b908687cc92957f459744dd34e85d42a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Thu, 15 May 2025 10:59:57 +0900 Subject: [PATCH 1/5] Solution Reverse linked list --- reverse-linked-list/doitduri.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 reverse-linked-list/doitduri.swift diff --git a/reverse-linked-list/doitduri.swift b/reverse-linked-list/doitduri.swift new file mode 100644 index 000000000..46ad6036e --- /dev/null +++ b/reverse-linked-list/doitduri.swift @@ -0,0 +1,14 @@ +class Solution { + func reverseList(_ head: ListNode?) -> ListNode? { + var current = head, previous: ListNode? = nil + + while current != nil { + let next = current?.next + current?.next = previous + previous = current + current = next + } + + return previous + } +} From cfd3c2c8740e47ab818037b31eb083a9a3b2ab2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Fri, 16 May 2025 14:02:59 +0900 Subject: [PATCH 2/5] Solution Longest substring without repeating characters --- .../doitduri.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 longest-substring-without-repeating-characters/doitduri.swift diff --git a/longest-substring-without-repeating-characters/doitduri.swift b/longest-substring-without-repeating-characters/doitduri.swift new file mode 100644 index 000000000..9351d3af0 --- /dev/null +++ b/longest-substring-without-repeating-characters/doitduri.swift @@ -0,0 +1,20 @@ +class Solution { + func lengthOfLongestSubstring(_ s: String) -> Int { + var charIndexMap = [Character: Int]() + var maxLength = 0 + var startIndex = 0 + + for (i, char) in Array(s).enumerated() { + if let lastIndex = charIndexMap[char], lastIndex >= startIndex { + startIndex = lastIndex + 1 + } + + let currentLength = i - startIndex + 1 + maxLength = max(maxLength, currentLength) + + charIndexMap[char] = i + } + + return maxLength + } +} From 1c022352a86fb7d5dbbc34c0506d993e3293753f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=91=90=EB=A6=AC?= Date: Fri, 16 May 2025 14:52:02 +0900 Subject: [PATCH 3/5] Solution Number of islands --- number-of-islands/doitduri.swift | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 number-of-islands/doitduri.swift diff --git a/number-of-islands/doitduri.swift b/number-of-islands/doitduri.swift new file mode 100644 index 000000000..fbefd2ecb --- /dev/null +++ b/number-of-islands/doitduri.swift @@ -0,0 +1,34 @@ +class Solution { + func numIslands(_ grid: [[Character]]) -> Int { + guard !grid.isEmpty else { return 0 } + + let rows = grid.count + let colums = grid[0].count + var visited = grid + var islandCount = 0 + + func dfs(_ row: Int, _ col: Int) { + guard row >= 0 && row < rows && col >= 0 && col < colums && visited[row][col] == "1" else { + return + } + + visited[row][col] = "0" + + dfs(row - 1, col) + dfs(row + 1, col) + dfs(row, col - 1) + dfs(row, col + 1) + } + + for row in 0.. Date: Sat, 17 May 2025 20:53:03 +0900 Subject: [PATCH 4/5] Solution Unique paths --- unique-paths/doitduri.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 unique-paths/doitduri.swift diff --git a/unique-paths/doitduri.swift b/unique-paths/doitduri.swift new file mode 100644 index 000000000..4437894eb --- /dev/null +++ b/unique-paths/doitduri.swift @@ -0,0 +1,21 @@ +class Solution { + func uniquePaths(_ m: Int, _ n: Int) -> Int { + var dp = Array(repeating: Array(repeating: 0, count: n), count: m) + + for j in 0.. Date: Sat, 17 May 2025 21:52:22 +0900 Subject: [PATCH 5/5] Solution Set matrix zeroes --- set-matrix-zeroes/doitduri.swift | 60 ++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 set-matrix-zeroes/doitduri.swift diff --git a/set-matrix-zeroes/doitduri.swift b/set-matrix-zeroes/doitduri.swift new file mode 100644 index 000000000..ba441cd12 --- /dev/null +++ b/set-matrix-zeroes/doitduri.swift @@ -0,0 +1,60 @@ +class Solution { + func setZeroes(_ matrix: inout [[Int]]) { + let m = matrix.count + let n = matrix[0].count + + var firstRowHasZero = false + var firstColHasZero = false + + for i in 0..