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
44 changes: 44 additions & 0 deletions leetcode3/1034. Coloring A Border.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Solution:
def colorBorder(self, grid, row, col, color):
m = len(grid)
n = len(grid[0])

target = grid[row][col]
visited = [[False] * n for _ in range(m)]
border = []

directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def dfs(r, c):
visited[r][c] = True

is_border = False

for dr, dc in directions:
nr = r + dr
nc = c + dc

# 배열의 가장자리
if nr < 0 or nr >= m or nc < 0 or nc >= n:
is_border = True
continue

# 다른 색과 인접
if grid[nr][nc] != target:
is_border = True
continue

# 같은 색이고 아직 방문하지 않았다면 DFS
if not visited[nr][nc]:
dfs(nr, nc)

if is_border:
border.append((r, c))

dfs(row, col)

# border만 색칠
for r, c in border:
grid[r][c] = color

return grid
20 changes: 20 additions & 0 deletions leetcode3/김민제/3838_weighted-word-mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def mapWordWeights(words, weights):
arr = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
'r','s','t','u','v','w','x','y','z']
arr2 = ['z','y','x','w','v','u','t','s','r','q','p','o','n','m','l','k','j',
'i','h','g','f','e','d','c','b','a']
ret = ""

for word in words:
weight = 0
for n in range(len(word)):
weight += weights[arr.index(word[n])]
ret+=arr2[weight % 26]

return ret


words = ["abcd","def","xyz"]
weights = [5,3,12,14,1,2,3,2,10,6,6,9,7,8,7,10,8,9,6,9,9,8,3,7,7,2]

print(mapWordWeights(words,weights))