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/변지협/v3/1861. Rotating the Box.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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