Skip to content

Commit 81de612

Browse files
committed
1034,3838
1 parent 5b9b7a7 commit 81de612

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from collections import deque
2+
3+
class Solution:
4+
def colorBorder(self, grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:
5+
queue = deque()
6+
7+
m, n = len(grid), len(grid[0])
8+
9+
visited = [[0] * n] * m
10+
print(visited)
11+
12+
queue.append((col,row))
13+
dirs = [(0,1),(0,-1),(1,0),(-1,0)]
14+
15+
while True:
16+
if len(queue) == 0:
17+
break
18+
19+
x,y = queue.pop()
20+
visited[y][x] = 1
21+
22+
if x == 0 or x == n or y == 0 or y == m :
23+
grid[y][x] = color
24+
25+
for dx,dy in dirs:
26+
if
27+
28+
29+
30+
return grid
31+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
'''
3+
1. 아이디어 :
4+
alphabet dic, dic_rev 만들고, 이에 매핑해서 구한다.
5+
6+
2. 시간복잡도 :
7+
o(n * m) n: words 길이, m: word 길이
8+
3. 자료구조/알고리즘 :
9+
'''
10+
class Solution:
11+
def mapWordWeights(self, words: List[str], weights: List[int]) -> str:
12+
alphabet = 'abcdefghijklmnopqrstuvwxyz'
13+
dic = {}
14+
dic_rev = {}
15+
wn = len(weights)
16+
for i in range(wn):
17+
dic[alphabet[i]] = weights[i]
18+
dic_rev[25-i] = alphabet[i]
19+
20+
ans = ''
21+
for word in words:
22+
tmp = sum([dic[w] for w in word])
23+
ans += dic_rev[tmp%26]
24+
25+
return ans
26+
27+

0 commit comments

Comments
 (0)