From 454a7f55e44f050edcf1fccfbae171f029629a92 Mon Sep 17 00:00:00 2001 From: rimogsu Date: Thu, 10 Sep 2026 22:41:51 +0900 Subject: [PATCH] 1861 --- .../v3/1861. Rotating the Box.py" | 39 +++++++++++++++++++ ... Construct the Minimum Bitwise Array I.py" | 25 ++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/1861. Rotating the Box.py" create mode 100644 "leetcode3/\353\263\200\354\247\200\355\230\221/v3/3314. Construct the Minimum Bitwise Array I.py" diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1861. Rotating the Box.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1861. Rotating the Box.py" new file mode 100644 index 00000000..323c510d --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/1861. Rotating the Box.py" @@ -0,0 +1,39 @@ + +''' +1. 아이디어 : +90도 회전 후 bfs로 교환 + +2. 시간복잡도 : +o(n * m) + +3. 자료구조/알고리즘 : +''' + +from collections import deque +class Solution: + def rotateTheBox(self, boxGrid: List[List[str]]) -> List[List[str]]: + x = len(boxGrid[0]) + y = len(boxGrid) + tmp = [[] for _ in range(x)] + + for i in range(y-1, -1, -1): + for j in range(x): + tmp[j].append(boxGrid[i][j]) + + xlen = len(tmp[0]) + ylen = len(tmp) + + queue = deque() + for y in range(ylen): + for x in range(xlen): + if tmp[y][x] == '.': + queue.append((x,y)) + + while queue: + x,y = queue.popleft() + if y != 0 and tmp[y-1][x] == '#': + tmp[y-1][x] = '.' + tmp[y][x] = '#' + queue.append((x,y-1)) + + return tmp \ No newline at end of file diff --git "a/leetcode3/\353\263\200\354\247\200\355\230\221/v3/3314. Construct the Minimum Bitwise Array I.py" "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/3314. Construct the Minimum Bitwise Array I.py" new file mode 100644 index 00000000..d250070c --- /dev/null +++ "b/leetcode3/\353\263\200\354\247\200\355\230\221/v3/3314. Construct the Minimum Bitwise Array I.py" @@ -0,0 +1,25 @@ + +''' +1. 아이디어 : +주어진 배열에서 각 요소에 대해 가장 작은 비트wise OR 값을 찾는다. + +2. 시간복잡도 : +o(n^2) + +3. 자료구조/알고리즘 : +''' + +class Solution: + def minBitwiseArray(self, nums: List[int]) -> List[int]: + n = len(nums) + ans = [-1] * n + for i in range(n): + for j in range(nums[i]): + if j | j+1 == nums[i]: + ans[i] = j + break + + return ans + + + \ No newline at end of file