Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions longest-substring-without-repeating-characters/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions reverse-linked-list/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions set-matrix-zeroes/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions unique-paths/hu6r1s.py
Original file line number Diff line number Diff line change
@@ -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]