Skip to content

Commit a9a1306

Browse files
authored
Merge pull request #1887 from hu6r1s/main
[hu6r1s] WEEK 07 Solutions
2 parents bc5b926 + aedf76f commit a9a1306

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
"""
3+
a => μ„ΈνŠΈ {}에 a μ—†μŒ
4+
ab => μ„ΈνŠΈ {a}에 b μ—†μŒ
5+
aba => μ„ΈνŠΈ {a, b}에 a 있음 => 쀑볡
6+
abac => 더 이상 κ³ λ € κ°€μΉ˜ μ—†μŒ
7+
"""
8+
def lengthOfLongestSubstring(self, s: str) -> int:
9+
max_len = 0
10+
for start in range(len(s)):
11+
chars = set()
12+
for end in range(start, len(s)):
13+
if s[end] in chars:
14+
break
15+
chars.add(s[end])
16+
max_len = max(end - start + 1, max_len)
17+
return max_len
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, val=0, next=None):
4+
# self.val = val
5+
# self.next = next
6+
class Solution:
7+
"""
8+
λ§ν¬λ“œ 리슀트 ν•™μŠ΅μ„ λ”°λ‘œ ν•΄μ•Όν•  ν•„μš”μ„±μ΄ 있음
9+
"""
10+
def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
11+
stack = []
12+
node = head
13+
while node:
14+
stack.append(node)
15+
node = node.next
16+
17+
dummy = ListNode()
18+
output = dummy
19+
while stack:
20+
output.next = stack.pop()
21+
output = output.next
22+
23+
output.next = None
24+
return dummy.next

β€Žset-matrix-zeroes/hu6r1s.pyβ€Ž

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution:
2+
def setZeroes(self, matrix: List[List[int]]) -> None:
3+
"""
4+
Do not return anything, modify matrix in-place instead.
5+
"""
6+
zero = []
7+
for i in range(len(matrix)):
8+
for j in range(len(matrix[0])):
9+
if matrix[i][j] == 0:
10+
zero.append((i, j))
11+
12+
for x, y in zero:
13+
for i in range(len(matrix[0])):
14+
matrix[x][i] = 0
15+
for i in range(len(matrix)):
16+
matrix[i][y] = 0

β€Žunique-paths/hu6r1s.pyβ€Ž

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
"""
3+
dfs둜 ν’€λ©΄ 될 것이라고 생각은 ν–ˆμ§€λ§Œ 이전 λ¬Έμ œμ™€ 같은 방식일 쀄 μ•Œμ•˜λŠ”λ° μ΄λŸ¬ν•œ 방식이 μžˆλŠ” 것을 μ•Œμ•˜μŒ
4+
"""
5+
# def uniquePaths(self, m: int, n: int) -> int:
6+
# def dfs(x, y):
7+
# if x == m - 1 and y == n - 1:
8+
# return 1
9+
# if x >= m or y >= n:
10+
# return 0
11+
12+
# return dfs(x + 1, y) + dfs(x, y + 1)
13+
14+
# return dfs(0, 0)
15+
16+
def uniquePaths(self, m: int, n: int) -> int:
17+
dp = [[1] * n for _ in range(m)]
18+
19+
for row in range(1, m):
20+
for col in range(1, n):
21+
dp[row][col] = dp[row - 1][col] + dp[row][col - 1]
22+
23+
return dp[-1][-1]

0 commit comments

Comments
Β (0)