Skip to content

Commit 717a9fa

Browse files
Merge pull request #2006 from CodingTestStudy2/변지협
[변지협] Day10
2 parents ef965b7 + 454a7f5 commit 717a9fa

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
'''
3+
1. 아이디어 :
4+
90도 회전 후 bfs로 교환
5+
6+
2. 시간복잡도 :
7+
o(n * m)
8+
9+
3. 자료구조/알고리즘 :
10+
'''
11+
12+
from collections import deque
13+
class Solution:
14+
def rotateTheBox(self, boxGrid: List[List[str]]) -> List[List[str]]:
15+
x = len(boxGrid[0])
16+
y = len(boxGrid)
17+
tmp = [[] for _ in range(x)]
18+
19+
for i in range(y-1, -1, -1):
20+
for j in range(x):
21+
tmp[j].append(boxGrid[i][j])
22+
23+
xlen = len(tmp[0])
24+
ylen = len(tmp)
25+
26+
queue = deque()
27+
for y in range(ylen):
28+
for x in range(xlen):
29+
if tmp[y][x] == '.':
30+
queue.append((x,y))
31+
32+
while queue:
33+
x,y = queue.popleft()
34+
if y != 0 and tmp[y-1][x] == '#':
35+
tmp[y-1][x] = '.'
36+
tmp[y][x] = '#'
37+
queue.append((x,y-1))
38+
39+
return tmp
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
'''
3+
1. 아이디어 :
4+
주어진 배열에서 각 요소에 대해 가장 작은 비트wise OR 값을 찾는다.
5+
6+
2. 시간복잡도 :
7+
o(n^2)
8+
9+
3. 자료구조/알고리즘 :
10+
'''
11+
12+
class Solution:
13+
def minBitwiseArray(self, nums: List[int]) -> List[int]:
14+
n = len(nums)
15+
ans = [-1] * n
16+
for i in range(n):
17+
for j in range(nums[i]):
18+
if j | j+1 == nums[i]:
19+
ans[i] = j
20+
break
21+
22+
return ans
23+
24+
25+

0 commit comments

Comments
 (0)