From 81de6122d262dcc14c87802f9ddee316ba89e752 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Tue, 18 Aug 2026 22:41:36 +0900 Subject: [PATCH 1/2] 1034,3838 --- .../v2/1034. Coloring A Border.py" | 31 +++++++++++++++++++ .../v2/3838. Weighted Word Mapping.py" | 27 ++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v2/3838. Weighted Word Mapping.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" new file mode 100644 index 00000000..1fd07ff6 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" @@ -0,0 +1,31 @@ +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] * m + print(visited) + + queue.append((col,row)) + dirs = [(0,1),(0,-1),(1,0),(-1,0)] + + while True: + if len(queue) == 0: + break + + x,y = queue.pop() + visited[y][x] = 1 + + if x == 0 or x == n or y == 0 or y == m : + grid[y][x] = color + + for dx,dy in dirs: + if + + + + return grid + \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3838. Weighted Word Mapping.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3838. Weighted Word Mapping.py" new file mode 100644 index 00000000..3451d4e2 --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/3838. Weighted Word Mapping.py" @@ -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 + + \ No newline at end of file From b1fd13c4ecf6ec9d2661d88b9c97c93d08205348 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Tue, 18 Aug 2026 23:37:51 +0900 Subject: [PATCH 2/2] =?UTF-8?q?1034=20=EC=9E=AC=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v2/1034. Coloring A Border.py" | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" index 1fd07ff6..b038114c 100644 --- "a/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v2/1034. Coloring A Border.py" @@ -6,26 +6,34 @@ def colorBorder(self, grid: List[List[int]], row: int, col: int, color: int) -> m, n = len(grid), len(grid[0]) - visited = [[0] * n] * m - print(visited) + 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.pop() + x,y = queue.popleft() visited[y][x] = 1 - if x == 0 or x == n or y == 0 or y == m : - grid[y][x] = color + 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 - - - + 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 \ No newline at end of file