From 76ef6c2070e82124230d48c27ae272692845618d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=80=EB=AF=BC=20=28E=2EM=2E=20Jamie=20Lee=29?= <100mgml@gmail.com> Date: Wed, 15 Apr 2026 13:33:11 +0900 Subject: [PATCH 1/7] add solution for uniquePaths --- unique-paths/gcount85.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 unique-paths/gcount85.py diff --git a/unique-paths/gcount85.py b/unique-paths/gcount85.py new file mode 100644 index 0000000000..feee38c30e --- /dev/null +++ b/unique-paths/gcount85.py @@ -0,0 +1,16 @@ +""" +# Approach +(0,0) -> (m-1, n-1)로 가기 위해서는 아래로는 m-1회, 우측으로 n-1회 이동해야 합니다. +도합 m+n-2회 이동해야 합니다. 그 이동 경로 중에서 방향 전환(우측 이동 혹은 아래쪽 이동)을 하는 경우의 수를 계산하여 unique path를 구합니다. + +# Complexity +- Time complexity: math.comb는 거의 상수 시간으로 취급하므로 O(1) +- Space complexity: O(1) +""" + +import math + + +class Solution: + def uniquePaths(self, m: int, n: int) -> int: + return math.comb(m + n - 2, m - 1) From 6c5cb3d6d0e8f746f9fa5230bd4ecd6f03facf35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=80=EB=AF=BC=20=28E=2EM=2E=20Jamie=20Lee=29?= <100mgml@gmail.com> Date: Wed, 15 Apr 2026 13:58:44 +0900 Subject: [PATCH 2/7] add setZeroes --- set-matrix-zeroes/gcount85.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 set-matrix-zeroes/gcount85.py diff --git a/set-matrix-zeroes/gcount85.py b/set-matrix-zeroes/gcount85.py new file mode 100644 index 0000000000..f9f51d4c9d --- /dev/null +++ b/set-matrix-zeroes/gcount85.py @@ -0,0 +1,34 @@ +""" +# Approach +matrix를 순회하며 값이 0인 행과 열의 번호를 기록합니다. +기록한 것을 토대로 다시 matrix를 순회하며 0으로 채웁니다. + +# Complexity +matrix의 행 크기를 M, 열 크기를 N이라고 할 때 +- Time complexity: O(MN) +- Space complexity: O(M+N) +""" + + +class Solution: + def setZeroes(self, matrix: list[list[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + + rows, cols = len(matrix), len(matrix[0]) + zero_rows = set() + zero_cols = set() + for x, row in enumerate(matrix): + for y, value in enumerate(row): + if value == 0: + zero_rows.add(x) + zero_cols.add(y) + + for x in zero_rows: + for i in range(cols): + matrix[x][i] = 0 + + for y in zero_cols: + for i in range(rows): + matrix[i][y] = 0 From 448462fda70c14499f01052c2f5f3b1d3ddecf92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=80=EB=AF=BC=20=28E=2EM=2E=20Jamie=20Lee=29?= <100mgml@gmail.com> Date: Thu, 16 Apr 2026 15:05:40 +0900 Subject: [PATCH 3/7] add reverseList function to reverse a linked list --- reverse-linked-list/gcount85.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 reverse-linked-list/gcount85.py diff --git a/reverse-linked-list/gcount85.py b/reverse-linked-list/gcount85.py new file mode 100644 index 0000000000..4059965740 --- /dev/null +++ b/reverse-linked-list/gcount85.py @@ -0,0 +1,22 @@ +""" +# Approach +이전 노드, 현재 노드, 다음 노드를 저장한 뒤, 현재 노드가 이전 노드를 가리키도록 방향을 바꾸고, +이전 노드와 현재 노드 포인터를 이동시킵니다. + +# Complexity +List의 길이를 N이라고 할 떄 +- Time complexity: O(N) +- Space complexity: O(1) +""" + + +class Solution: + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + prev = None + cur = head + while cur: + nxt = cur.next # 1. 다음 노드 저장 + cur.next = prev # 2. 방향 뒤집기 + prev = cur # 3. prev 이동 + cur = nxt # 4. cur 이동 + return prev From c52f8f2f8d954c0606e130ac481538afdf59485e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=80=EB=AF=BC=20=28E=2EM=2E=20Jamie=20Lee=29?= <100mgml@gmail.com> Date: Thu, 16 Apr 2026 15:11:51 +0900 Subject: [PATCH 4/7] add numIslands function to count the number of islands in a grid --- number-of-islands/gcount85.py | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 number-of-islands/gcount85.py diff --git a/number-of-islands/gcount85.py b/number-of-islands/gcount85.py new file mode 100644 index 0000000000..83a90ca814 --- /dev/null +++ b/number-of-islands/gcount85.py @@ -0,0 +1,45 @@ +""" +# Approach +Grid의 원소에 일일이 dfs를 수행하되 값이 "1"(=육지)인 경우만 탐색을 수행합니다. +이때 방문한 노드는 값을 "-1"로 변경하여 방문 체크합니다. + +# Complexity +Grid의 rows = M, cols = N이라고 할 때, +- Time complexity: O(M*N) +- Space complexity: visited set 최대 O(M*N) +""" + + +class Solution: + def numIslands(self, grid: List[List[str]]) -> int: + answer = 0 + direction = [(0, 1), (0, -1), (1, 0), (-1, 0)] + row = len(grid) + col = len(grid[0]) + + def can_go(x, y, row, col): + if x < 0 or y < 0 or x >= row or y >= col: + return False + if grid[x][y] == "0": + return False + return True + + def dfs(x, y, row, col): + for dx, dy in direction: + nx, ny = x + dx, y + dy + if not can_go(nx, ny, row, col): + continue + if grid[nx][ny] == "-1": # 방문 확인 + continue + grid[nx][ny] = "-1" # 방문 처리 + dfs(nx, ny, row, col) + + for x, row_list in enumerate(grid): + for y, value in enumerate(row_list): + if value != "1": + continue + grid[x][y] = "-1" # 방문 확인 + dfs(x, y, row, col) + answer += 1 + + return answer From 37934ddc346496ab6b03b948171666882fe7208a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=9D=80=EB=AF=BC=20=28E=2EM=2E=20Jamie=20Lee=29?= <100mgml@gmail.com> Date: Thu, 16 Apr 2026 15:16:22 +0900 Subject: [PATCH 5/7] add solution for longest substring without repeating characters problem --- .../gcount85.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 longest-substring-without-repeating-characters/gcount85.py diff --git a/longest-substring-without-repeating-characters/gcount85.py b/longest-substring-without-repeating-characters/gcount85.py new file mode 100644 index 0000000000..2701a819d3 --- /dev/null +++ b/longest-substring-without-repeating-characters/gcount85.py @@ -0,0 +1,33 @@ +""" +# Approach +슬라이딩 윈도우를 사용한다. +right 포인터를 하나씩 이동시키면서 문자열을 확장하고, +이미 등장한 문자를 만나면 해당 문자의 마지막 위치를 기준으로 left 포인터를 이동시켜 중복이 없는 구간을 유지한다. +각 단계에서 현재 윈도우의 길이를 계산하여 최대값을 갱신한다. + +# Complexity +문자열 길이를 N이라고 할 때, 문자 종류 수를 K라고 할 때 +- Time complexity: O(N) +- Space complexity: O(K) +""" + + +class Solution: + def lengthOfLongestSubstring(self, s: str) -> int: + last_seen = {} # 문자 -> 마지막으로 등장한 인덱스 + left = 0 # 현재 윈도우의 시작 위치 + answer = 0 # 최대 길이 저장 + + for right, ch in enumerate(s): + # 현재 문자가 이전에 등장했고, + # 그 위치가 현재 윈도우 안에 있다면 left 이동 + if ch in last_seen and last_seen[ch] >= left: + left = last_seen[ch] + 1 + + # 현재 문자의 마지막 위치 갱신 + last_seen[ch] = right + + # 현재 윈도우 길이 계산 및 최대값 갱신 + answer = max(answer, right - left + 1) + + return answer From 858dab7dac64f69d45bd387d74318336a1c4544e Mon Sep 17 00:00:00 2001 From: jamiebase <100mgml@gmail.com> Date: Fri, 17 Apr 2026 12:47:01 +0900 Subject: [PATCH 6/7] Update filenames --- .../{gcount85.py => jamiebase.py} | 0 number-of-islands/{gcount85.py => jamiebase.py} | 0 reverse-linked-list/{gcount85.py => jamiebase.py} | 0 set-matrix-zeroes/{gcount85.py => jamiebase.py} | 0 unique-paths/{gcount85.py => jamiebase.py} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename longest-substring-without-repeating-characters/{gcount85.py => jamiebase.py} (100%) rename number-of-islands/{gcount85.py => jamiebase.py} (100%) rename reverse-linked-list/{gcount85.py => jamiebase.py} (100%) rename set-matrix-zeroes/{gcount85.py => jamiebase.py} (100%) rename unique-paths/{gcount85.py => jamiebase.py} (100%) diff --git a/longest-substring-without-repeating-characters/gcount85.py b/longest-substring-without-repeating-characters/jamiebase.py similarity index 100% rename from longest-substring-without-repeating-characters/gcount85.py rename to longest-substring-without-repeating-characters/jamiebase.py diff --git a/number-of-islands/gcount85.py b/number-of-islands/jamiebase.py similarity index 100% rename from number-of-islands/gcount85.py rename to number-of-islands/jamiebase.py diff --git a/reverse-linked-list/gcount85.py b/reverse-linked-list/jamiebase.py similarity index 100% rename from reverse-linked-list/gcount85.py rename to reverse-linked-list/jamiebase.py diff --git a/set-matrix-zeroes/gcount85.py b/set-matrix-zeroes/jamiebase.py similarity index 100% rename from set-matrix-zeroes/gcount85.py rename to set-matrix-zeroes/jamiebase.py diff --git a/unique-paths/gcount85.py b/unique-paths/jamiebase.py similarity index 100% rename from unique-paths/gcount85.py rename to unique-paths/jamiebase.py From 8ae1b5ead7201231067d441fb3c9e39f84da3c7f Mon Sep 17 00:00:00 2001 From: jamiebase <100mgml@gmail.com> Date: Fri, 17 Apr 2026 12:54:09 +0900 Subject: [PATCH 7/7] Update filenames to jamiebase.py --- 3sum/{gcount85.py => jamiebase.py} | 0 best-time-to-buy-and-sell-stock/{gcount85.py => jamiebase.py} | 0 climbing-stairs/{gcount85.py => jamiebase.py} | 0 coin-change/{gcount85.py => jamiebase.py} | 0 combination-sum/{gcount85.py => jamiebase.py} | 0 container-with-most-water/{gcount85.py => jamiebase.py} | 0 contains-duplicate/{gcount85.py => jamiebase.py} | 0 decode-ways/{gcount85.py => jamiebase.py} | 0 .../{gcount85.py => jamiebase.py} | 0 group-anagrams/{gcount85.py => jamiebase.py} | 0 house-robber/{gcount85.py => jamiebase.py} | 0 implement-trie-prefix-tree/{gcount85.py => jamiebase.py} | 0 longest-consecutive-sequence/{gcount85.py => jamiebase.py} | 0 longest-increasing-subsequence/{gcount85.py => jamiebase.py} | 0 maximum-depth-of-binary-tree/{gcount85.py => jamiebase.py} | 0 maximum-subarray/{gcount85.py => jamiebase.py} | 0 merge-two-sorted-lists/{gcount85.py => jamiebase.py} | 0 number-of-1-bits/{gcount85.py => jamiebase.py} | 0 product-of-array-except-self/{gcount85.py => jamiebase.py} | 0 spiral-matrix/{gcount85.py => jamiebase.py} | 0 top-k-frequent-elements/{gcount85.py => jamiebase.py} | 0 two-sum/{gcount85.py => jamiebase.py} | 0 valid-anagram/{gcount85.py => jamiebase.py} | 0 valid-palindrome/{gcount85.py => jamiebase.py} | 0 valid-parentheses/{gcount85.py => jamiebase.py} | 0 validate-binary-search-tree/{gcount85.py => jamiebase.py} | 0 word-break/{gcount85.py => jamiebase.py} | 0 word-search/{gcount85.py => jamiebase.py} | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename 3sum/{gcount85.py => jamiebase.py} (100%) rename best-time-to-buy-and-sell-stock/{gcount85.py => jamiebase.py} (100%) rename climbing-stairs/{gcount85.py => jamiebase.py} (100%) rename coin-change/{gcount85.py => jamiebase.py} (100%) rename combination-sum/{gcount85.py => jamiebase.py} (100%) rename container-with-most-water/{gcount85.py => jamiebase.py} (100%) rename contains-duplicate/{gcount85.py => jamiebase.py} (100%) rename decode-ways/{gcount85.py => jamiebase.py} (100%) rename find-minimum-in-rotated-sorted-array/{gcount85.py => jamiebase.py} (100%) rename group-anagrams/{gcount85.py => jamiebase.py} (100%) rename house-robber/{gcount85.py => jamiebase.py} (100%) rename implement-trie-prefix-tree/{gcount85.py => jamiebase.py} (100%) rename longest-consecutive-sequence/{gcount85.py => jamiebase.py} (100%) rename longest-increasing-subsequence/{gcount85.py => jamiebase.py} (100%) rename maximum-depth-of-binary-tree/{gcount85.py => jamiebase.py} (100%) rename maximum-subarray/{gcount85.py => jamiebase.py} (100%) rename merge-two-sorted-lists/{gcount85.py => jamiebase.py} (100%) rename number-of-1-bits/{gcount85.py => jamiebase.py} (100%) rename product-of-array-except-self/{gcount85.py => jamiebase.py} (100%) rename spiral-matrix/{gcount85.py => jamiebase.py} (100%) rename top-k-frequent-elements/{gcount85.py => jamiebase.py} (100%) rename two-sum/{gcount85.py => jamiebase.py} (100%) rename valid-anagram/{gcount85.py => jamiebase.py} (100%) rename valid-palindrome/{gcount85.py => jamiebase.py} (100%) rename valid-parentheses/{gcount85.py => jamiebase.py} (100%) rename validate-binary-search-tree/{gcount85.py => jamiebase.py} (100%) rename word-break/{gcount85.py => jamiebase.py} (100%) rename word-search/{gcount85.py => jamiebase.py} (100%) diff --git a/3sum/gcount85.py b/3sum/jamiebase.py similarity index 100% rename from 3sum/gcount85.py rename to 3sum/jamiebase.py diff --git a/best-time-to-buy-and-sell-stock/gcount85.py b/best-time-to-buy-and-sell-stock/jamiebase.py similarity index 100% rename from best-time-to-buy-and-sell-stock/gcount85.py rename to best-time-to-buy-and-sell-stock/jamiebase.py diff --git a/climbing-stairs/gcount85.py b/climbing-stairs/jamiebase.py similarity index 100% rename from climbing-stairs/gcount85.py rename to climbing-stairs/jamiebase.py diff --git a/coin-change/gcount85.py b/coin-change/jamiebase.py similarity index 100% rename from coin-change/gcount85.py rename to coin-change/jamiebase.py diff --git a/combination-sum/gcount85.py b/combination-sum/jamiebase.py similarity index 100% rename from combination-sum/gcount85.py rename to combination-sum/jamiebase.py diff --git a/container-with-most-water/gcount85.py b/container-with-most-water/jamiebase.py similarity index 100% rename from container-with-most-water/gcount85.py rename to container-with-most-water/jamiebase.py diff --git a/contains-duplicate/gcount85.py b/contains-duplicate/jamiebase.py similarity index 100% rename from contains-duplicate/gcount85.py rename to contains-duplicate/jamiebase.py diff --git a/decode-ways/gcount85.py b/decode-ways/jamiebase.py similarity index 100% rename from decode-ways/gcount85.py rename to decode-ways/jamiebase.py diff --git a/find-minimum-in-rotated-sorted-array/gcount85.py b/find-minimum-in-rotated-sorted-array/jamiebase.py similarity index 100% rename from find-minimum-in-rotated-sorted-array/gcount85.py rename to find-minimum-in-rotated-sorted-array/jamiebase.py diff --git a/group-anagrams/gcount85.py b/group-anagrams/jamiebase.py similarity index 100% rename from group-anagrams/gcount85.py rename to group-anagrams/jamiebase.py diff --git a/house-robber/gcount85.py b/house-robber/jamiebase.py similarity index 100% rename from house-robber/gcount85.py rename to house-robber/jamiebase.py diff --git a/implement-trie-prefix-tree/gcount85.py b/implement-trie-prefix-tree/jamiebase.py similarity index 100% rename from implement-trie-prefix-tree/gcount85.py rename to implement-trie-prefix-tree/jamiebase.py diff --git a/longest-consecutive-sequence/gcount85.py b/longest-consecutive-sequence/jamiebase.py similarity index 100% rename from longest-consecutive-sequence/gcount85.py rename to longest-consecutive-sequence/jamiebase.py diff --git a/longest-increasing-subsequence/gcount85.py b/longest-increasing-subsequence/jamiebase.py similarity index 100% rename from longest-increasing-subsequence/gcount85.py rename to longest-increasing-subsequence/jamiebase.py diff --git a/maximum-depth-of-binary-tree/gcount85.py b/maximum-depth-of-binary-tree/jamiebase.py similarity index 100% rename from maximum-depth-of-binary-tree/gcount85.py rename to maximum-depth-of-binary-tree/jamiebase.py diff --git a/maximum-subarray/gcount85.py b/maximum-subarray/jamiebase.py similarity index 100% rename from maximum-subarray/gcount85.py rename to maximum-subarray/jamiebase.py diff --git a/merge-two-sorted-lists/gcount85.py b/merge-two-sorted-lists/jamiebase.py similarity index 100% rename from merge-two-sorted-lists/gcount85.py rename to merge-two-sorted-lists/jamiebase.py diff --git a/number-of-1-bits/gcount85.py b/number-of-1-bits/jamiebase.py similarity index 100% rename from number-of-1-bits/gcount85.py rename to number-of-1-bits/jamiebase.py diff --git a/product-of-array-except-self/gcount85.py b/product-of-array-except-self/jamiebase.py similarity index 100% rename from product-of-array-except-self/gcount85.py rename to product-of-array-except-self/jamiebase.py diff --git a/spiral-matrix/gcount85.py b/spiral-matrix/jamiebase.py similarity index 100% rename from spiral-matrix/gcount85.py rename to spiral-matrix/jamiebase.py diff --git a/top-k-frequent-elements/gcount85.py b/top-k-frequent-elements/jamiebase.py similarity index 100% rename from top-k-frequent-elements/gcount85.py rename to top-k-frequent-elements/jamiebase.py diff --git a/two-sum/gcount85.py b/two-sum/jamiebase.py similarity index 100% rename from two-sum/gcount85.py rename to two-sum/jamiebase.py diff --git a/valid-anagram/gcount85.py b/valid-anagram/jamiebase.py similarity index 100% rename from valid-anagram/gcount85.py rename to valid-anagram/jamiebase.py diff --git a/valid-palindrome/gcount85.py b/valid-palindrome/jamiebase.py similarity index 100% rename from valid-palindrome/gcount85.py rename to valid-palindrome/jamiebase.py diff --git a/valid-parentheses/gcount85.py b/valid-parentheses/jamiebase.py similarity index 100% rename from valid-parentheses/gcount85.py rename to valid-parentheses/jamiebase.py diff --git a/validate-binary-search-tree/gcount85.py b/validate-binary-search-tree/jamiebase.py similarity index 100% rename from validate-binary-search-tree/gcount85.py rename to validate-binary-search-tree/jamiebase.py diff --git a/word-break/gcount85.py b/word-break/jamiebase.py similarity index 100% rename from word-break/gcount85.py rename to word-break/jamiebase.py diff --git a/word-search/gcount85.py b/word-search/jamiebase.py similarity index 100% rename from word-search/gcount85.py rename to word-search/jamiebase.py