-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1861_Rotating_the_Box.py
More file actions
30 lines (29 loc) · 1.09 KB
/
1861_Rotating_the_Box.py
File metadata and controls
30 lines (29 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution:
def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:
m = len(box)
n = len(box[0])
sol = [[""] * m for _ in range(n)]
stone_list = []
for index_m, each_m in enumerate(box):
for index_n, each_n in enumerate(each_m):
if not each_n == "#":
sol[index_n][m - index_m - 1] = each_n
else:
sol[index_n][m - index_m - 1] = "."
stone_list.append((index_n, m - index_m - 1))
for s_m, s_n in stone_list:
if sol[s_m][s_n] == "#":
while sol[s_m][s_n] == "#":
s_m -= 1
sol[s_m][s_n] = "#"
else:
while sol[s_m][s_n] == ".":
if s_m == n-1:
sol[s_m][s_n] = "#"
break
elif sol[s_m+1][s_n] == "*" or sol[s_m+1][s_n] == "#":
sol[s_m][s_n] = "#"
break
else:
s_m += 1
return sol