From 671f5f67d57b24b1a5ba4bfc4455da7c75aadfcc Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Mon, 3 Aug 2026 21:37:58 +0900 Subject: [PATCH 1/7] reverse linked list solution --- reverse-linked-list/dolphinflow86.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 reverse-linked-list/dolphinflow86.py diff --git a/reverse-linked-list/dolphinflow86.py b/reverse-linked-list/dolphinflow86.py new file mode 100644 index 0000000000..905079f98a --- /dev/null +++ b/reverse-linked-list/dolphinflow86.py @@ -0,0 +1,16 @@ +# TC: O(N) - visits each node exactly once +# SC: O(1) - reverses the links in place +class Solution: + + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + prev = None + current = head + + while current: + next_node = current.next + current.next = prev + prev = current + current = next_node + + return prev + From 925fad36661eb38ed62dd24eb0f59cc03c1cd8f4 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Tue, 4 Aug 2026 23:06:04 +0900 Subject: [PATCH 2/7] longest substring without repeating characters solution --- .../dolphinflow86.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 longest-substring-without-repeating-characters/dolphinflow86.py diff --git a/longest-substring-without-repeating-characters/dolphinflow86.py b/longest-substring-without-repeating-characters/dolphinflow86.py new file mode 100644 index 0000000000..7d0f78f68f --- /dev/null +++ b/longest-substring-without-repeating-characters/dolphinflow86.py @@ -0,0 +1,20 @@ +# N is the length of s. +# TC: O(N) - each character is added and removed at most once +# SC: O(N) - stores the characters in the current window +class Solution: + + def lengthOfLongestSubstring(self, s: str) -> int: + chars = set() + left = 0 + longest = 0 + + for right, char in enumerate(s): + while char in chars: + chars.remove(s[left]) + left += 1 + + chars.add(char) + longest = max(longest, right - left + 1) + + return longest + From fe7b603126cd8208bf5b25dbe8aba6485c4c9324 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Wed, 5 Aug 2026 22:19:58 +0900 Subject: [PATCH 3/7] number of islands solution --- number-of-islands/dolphinflow86.py | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 number-of-islands/dolphinflow86.py diff --git a/number-of-islands/dolphinflow86.py b/number-of-islands/dolphinflow86.py new file mode 100644 index 0000000000..0a9760a273 --- /dev/null +++ b/number-of-islands/dolphinflow86.py @@ -0,0 +1,36 @@ +# R is the number of rows, and C is the number of columns. +# TC: O(R * C) - visits each cell at most once +# SC: O(R * C) - uses the recursion stack in the worst case +class Solution: + + def numIslands(self, grid: List[List[str]]) -> int: + rows = len(grid) + cols = len(grid[0]) + + def dfs(row, col): + if ( + row < 0 + or row >= rows + or col < 0 + or col >= cols + or grid[row][col] != "1" + ): + return + + grid[row][col] = "0" + + dfs(row - 1, col) + dfs(row + 1, col) + dfs(row, col - 1) + dfs(row, col + 1) + + islands = 0 + + for row in range(rows): + for col in range(cols): + if grid[row][col] == "1": + islands += 1 + dfs(row, col) + + return islands + From 7d34a68e234482c844a7dddd9bda2a358b19f208 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Thu, 6 Aug 2026 20:53:25 +0900 Subject: [PATCH 4/7] update variable naming --- number-of-islands/dolphinflow86.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/number-of-islands/dolphinflow86.py b/number-of-islands/dolphinflow86.py index 0a9760a273..68dd080f4a 100644 --- a/number-of-islands/dolphinflow86.py +++ b/number-of-islands/dolphinflow86.py @@ -4,15 +4,15 @@ class Solution: def numIslands(self, grid: List[List[str]]) -> int: - rows = len(grid) - cols = len(grid[0]) + row_count = len(grid) + column_count = len(grid[0]) def dfs(row, col): if ( row < 0 - or row >= rows + or row >= row_count or col < 0 - or col >= cols + or col >= column_count or grid[row][col] != "1" ): return @@ -24,13 +24,13 @@ def dfs(row, col): dfs(row, col - 1) dfs(row, col + 1) - islands = 0 + island_count = 0 - for row in range(rows): - for col in range(cols): + for row in range(row_count): + for col in range(column_count): if grid[row][col] == "1": - islands += 1 + island_count += 1 dfs(row, col) - return islands + return island_count From f4edd34b0e112c4f7af0a2998cf9427b48e2f880 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sat, 8 Aug 2026 12:18:07 +0900 Subject: [PATCH 5/7] update line breaks --- longest-substring-without-repeating-characters/dolphinflow86.py | 1 - number-of-islands/dolphinflow86.py | 1 - reverse-linked-list/dolphinflow86.py | 1 - 3 files changed, 3 deletions(-) diff --git a/longest-substring-without-repeating-characters/dolphinflow86.py b/longest-substring-without-repeating-characters/dolphinflow86.py index 7d0f78f68f..f171063a4a 100644 --- a/longest-substring-without-repeating-characters/dolphinflow86.py +++ b/longest-substring-without-repeating-characters/dolphinflow86.py @@ -17,4 +17,3 @@ def lengthOfLongestSubstring(self, s: str) -> int: longest = max(longest, right - left + 1) return longest - diff --git a/number-of-islands/dolphinflow86.py b/number-of-islands/dolphinflow86.py index 68dd080f4a..80f5079f88 100644 --- a/number-of-islands/dolphinflow86.py +++ b/number-of-islands/dolphinflow86.py @@ -33,4 +33,3 @@ def dfs(row, col): dfs(row, col) return island_count - diff --git a/reverse-linked-list/dolphinflow86.py b/reverse-linked-list/dolphinflow86.py index 905079f98a..8a5bf422a1 100644 --- a/reverse-linked-list/dolphinflow86.py +++ b/reverse-linked-list/dolphinflow86.py @@ -13,4 +13,3 @@ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: current = next_node return prev - From bb27223233f6aa758650b4adf7637d10c6d9dd77 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sat, 8 Aug 2026 12:19:24 +0900 Subject: [PATCH 6/7] unique paths solution --- unique-paths/dolphinflow86.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 unique-paths/dolphinflow86.py diff --git a/unique-paths/dolphinflow86.py b/unique-paths/dolphinflow86.py new file mode 100644 index 0000000000..76d68d93f4 --- /dev/null +++ b/unique-paths/dolphinflow86.py @@ -0,0 +1,24 @@ +# M is the number of rows, and N is the number of columns. +# TC: O(M * N) - calculates the number of paths from each cell once +# SC: O(M * N) - uses a memo dictionary and the recursion stack +class Solution: + + def dfs(self, row, col, m, n, memo): + if row == m - 1 and col == n - 1: + return 1 + + if row >= m or col >= n: + return 0 + + if (row, col) in memo: + return memo[(row, col)] + + memo[(row, col)] = ( + self.dfs(row + 1, col, m, n, memo) + + self.dfs(row, col + 1, m, n, memo) + ) + return memo[(row, col)] + + def uniquePaths(self, m: int, n: int) -> int: + memo = {} + return self.dfs(0, 0, m, n, memo) From 7980f0ae1f0e410cce7ef81677948e894dc12ac7 Mon Sep 17 00:00:00 2001 From: dolphinflow86 Date: Sat, 8 Aug 2026 12:19:36 +0900 Subject: [PATCH 7/7] set matrix zeroes solution --- set-matrix-zeroes/dolphinflow86.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 set-matrix-zeroes/dolphinflow86.py diff --git a/set-matrix-zeroes/dolphinflow86.py b/set-matrix-zeroes/dolphinflow86.py new file mode 100644 index 0000000000..751b3de18b --- /dev/null +++ b/set-matrix-zeroes/dolphinflow86.py @@ -0,0 +1,29 @@ +# R is the number of rows, and C is the number of columns. +# TC: O(R * C) - scans each cell a constant number of times +# SC: O(1) - uses the first row and column as markers +class Solution: + + def setZeroes(self, matrix: List[List[int]]) -> None: + row_count = len(matrix) + column_count = len(matrix[0]) + first_row_has_zero = any(matrix[0][col] == 0 for col in range(column_count)) + first_column_has_zero = any(matrix[row][0] == 0 for row in range(row_count)) + + for row in range(1, row_count): + for col in range(1, column_count): + if matrix[row][col] == 0: + matrix[row][0] = 0 + matrix[0][col] = 0 + + for row in range(1, row_count): + for col in range(1, column_count): + if matrix[row][0] == 0 or matrix[0][col] == 0: + matrix[row][col] = 0 + + if first_row_has_zero: + for col in range(column_count): + matrix[0][col] = 0 + + if first_column_has_zero: + for row in range(row_count): + matrix[row][0] = 0