Skip to content

Commit aafb8ad

Browse files
Merge pull request #1859 from CodingTestStudy2/남효정
[남효정] Day19, Day20
2 parents 6eac6ea + 22b56f5 commit aafb8ad

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 풀이 실패
2+
3+
class Solution:
4+
def colorBorder(self, grid: List[List[int]], row: int, col: int, color: int) -> List[List[int]]:
5+
m, n = len(grid), len(grid[0])
6+
target_color = grid[row][col]
7+
8+
queue = deque([(row, col)])
9+
visited = {(row, col)}
10+
borders = []
11+
12+
while queue:
13+
r, c = queue.popleft()
14+
is_border = False
15+
16+
# 상하좌우 4방향으로
17+
for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
18+
nr, nc = r + dr, c + dc
19+
20+
# 격자 밖이면 테두리임
21+
if not (0 <= nr < m and 0 <= nc < n):
22+
is_border = True
23+
24+
# 다른 색상이어도 테두리
25+
elif grid[nr][nc] != target_color:
26+
is_border = True
27+
28+
# 아직 안 가본 색상 칸이라면 큐에 추가함
29+
elif (nr, nc) not in visited:
30+
visited.add((nr, nc))
31+
queue.append((nr, nc))
32+
33+
# 테두리로 결정되면 기록
34+
if is_border:
35+
borders.append((r, c))
36+
37+
# 테두리 칸들만 색상 변경
38+
for r, c in borders:
39+
grid[r][c] = color
40+
41+
return grid
42+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def mapWordWeights(self, words: List[str], weights: List[int]) -> str:
3+
ans = []
4+
5+
# ord()의 합과 알파벳 거꾸로 정렬한 순서의 합이 항상 122인 것을 이용
6+
for word in words:
7+
sum_score = 0
8+
for char in word:
9+
sum_score += weights[ord(char)-97]
10+
ans.append(chr(122 - sum_score % 26))
11+
12+
return ''.join(ans)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# 문제 그대로 풀이하면 됨
2+
class Solution:
3+
def isMiddleElementUnique(self, nums: list[int]) -> bool:
4+
return nums.count(nums[len(nums) // 2]) == 1

0 commit comments

Comments
 (0)