From a82617bf931dcb04d02e727f40894b5983237a1f Mon Sep 17 00:00:00 2001 From: hu6r1s Date: Wed, 3 Sep 2025 18:22:34 +0900 Subject: [PATCH 1/4] feat: Solve reverse-linked-list problem --- reverse-linked-list/hu6r1s.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 reverse-linked-list/hu6r1s.py diff --git a/reverse-linked-list/hu6r1s.py b/reverse-linked-list/hu6r1s.py new file mode 100644 index 000000000..6fc37bb45 --- /dev/null +++ b/reverse-linked-list/hu6r1s.py @@ -0,0 +1,24 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, val=0, next=None): +# self.val = val +# self.next = next +class Solution: + """ + 링크드 리스트 학습을 따로 해야할 필요성이 있음 + """ + def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]: + stack = [] + node = head + while node: + stack.append(node) + node = node.next + + dummy = ListNode() + output = dummy + while stack: + output.next = stack.pop() + output = output.next + + output.next = None + return dummy.next From a1828aadaf07ff545c87a3bb1714759611f15870 Mon Sep 17 00:00:00 2001 From: hu6r1s Date: Fri, 5 Sep 2025 12:00:35 +0900 Subject: [PATCH 2/4] feat: Solve longest-substring-without-repeating-characters problem --- .../hu6r1s.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 longest-substring-without-repeating-characters/hu6r1s.py diff --git a/longest-substring-without-repeating-characters/hu6r1s.py b/longest-substring-without-repeating-characters/hu6r1s.py new file mode 100644 index 000000000..2cf72c135 --- /dev/null +++ b/longest-substring-without-repeating-characters/hu6r1s.py @@ -0,0 +1,17 @@ +class Solution: + """ + a => 세트 {}에 a 없음 + ab => 세트 {a}에 b 없음 + aba => 세트 {a, b}에 a 있음 => 중복 + abac => 더 이상 고려 가치 없음 + """ + def lengthOfLongestSubstring(self, s: str) -> int: + max_len = 0 + for start in range(len(s)): + chars = set() + for end in range(start, len(s)): + if s[end] in chars: + break + chars.add(s[end]) + max_len = max(end - start + 1, max_len) + return max_len From bba4a942b97a270853d9c2a2cc60410254a6ede3 Mon Sep 17 00:00:00 2001 From: hu6r1s Date: Fri, 5 Sep 2025 13:28:56 +0900 Subject: [PATCH 3/4] feat: Solve unique-paths problem --- unique-paths/hu6r1s.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 unique-paths/hu6r1s.py diff --git a/unique-paths/hu6r1s.py b/unique-paths/hu6r1s.py new file mode 100644 index 000000000..77c268ecd --- /dev/null +++ b/unique-paths/hu6r1s.py @@ -0,0 +1,23 @@ +class Solution: + """ + dfs로 풀면 될 것이라고 생각은 했지만 이전 문제와 같은 방식일 줄 알았는데 이러한 방식이 있는 것을 알았음 + """ + # def uniquePaths(self, m: int, n: int) -> int: + # def dfs(x, y): + # if x == m - 1 and y == n - 1: + # return 1 + # if x >= m or y >= n: + # return 0 + + # return dfs(x + 1, y) + dfs(x, y + 1) + + # return dfs(0, 0) + + def uniquePaths(self, m: int, n: int) -> int: + dp = [[1] * n for _ in range(m)] + + for row in range(1, m): + for col in range(1, n): + dp[row][col] = dp[row - 1][col] + dp[row][col - 1] + + return dp[-1][-1] From aedf76fcb043b8f32a059a2d8333512da4bb07e2 Mon Sep 17 00:00:00 2001 From: hu6r1s Date: Fri, 5 Sep 2025 13:38:40 +0900 Subject: [PATCH 4/4] feat: Solve set-matrix-zeroes problem --- set-matrix-zeroes/hu6r1s.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 set-matrix-zeroes/hu6r1s.py diff --git a/set-matrix-zeroes/hu6r1s.py b/set-matrix-zeroes/hu6r1s.py new file mode 100644 index 000000000..c58e4e84e --- /dev/null +++ b/set-matrix-zeroes/hu6r1s.py @@ -0,0 +1,16 @@ +class Solution: + def setZeroes(self, matrix: List[List[int]]) -> None: + """ + Do not return anything, modify matrix in-place instead. + """ + zero = [] + for i in range(len(matrix)): + for j in range(len(matrix[0])): + if matrix[i][j] == 0: + zero.append((i, j)) + + for x, y in zero: + for i in range(len(matrix[0])): + matrix[x][i] = 0 + for i in range(len(matrix)): + matrix[i][y] = 0