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
39 changes: 39 additions & 0 deletions leetcode3/변지협/v2/1034. Coloring A Border.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from collections import deque

class Solution:
def colorBorder(self, grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:
queue = deque()

m, n = len(grid), len(grid[0])

visited = [[0] * n for _ in range(m)]
tmp = [[0] * n for _ in range(m)]

queue.append((col,row))
c = grid[row][col]
dirs = [(0,1),(0,-1),(1,0),(-1,0)]


while True:
if len(queue) == 0:
break

x,y = queue.popleft()
visited[y][x] = 1

if x == 0 or x == n-1 or y == 0 or y == m-1:
tmp[y][x] = 1
elif not (grid[y+1][x] == c and grid[y-1][x] == c and grid[y][x+1] == c and grid[y][x-1] == c):
tmp[y][x] = 1

for dx,dy in dirs:
if 0 <= x + dx < n and 0 <= y + dy < m and visited[y+dy][x+dx] == 0 and grid[y+dy][x+dx] == c:
queue.append((x+dx,y+dy))

for y in range(m):
for x in range(n):
if tmp[y][x] == 1:
grid[y][x] = color

return grid

27 changes: 27 additions & 0 deletions leetcode3/변지협/v2/3838. Weighted Word Mapping.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

'''
1. 아이디어 :
alphabet dic, dic_rev 만들고, 이에 매핑해서 구한다.

2. 시간복잡도 :
o(n * m) n: words 길이, m: word 길이
3. 자료구조/알고리즘 :
'''
class Solution:
def mapWordWeights(self, words: List[str], weights: List[int]) -> str:
alphabet = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
dic_rev = {}
wn = len(weights)
for i in range(wn):
dic[alphabet[i]] = weights[i]
dic_rev[25-i] = alphabet[i]

ans = ''
for word in words:
tmp = sum([dic[w] for w in word])
ans += dic_rev[tmp%26]

return ans