-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy path1861-rotating-the-box.py
38 lines (29 loc) · 1.01 KB
/
1861-rotating-the-box.py
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
31
32
33
34
35
36
37
38
# time complexity: O(m*n)
# space complexity: O(m*n)
from typing import List
class Solution:
def rotateTheBox(self, box: List[List[str]]) -> List[List[str]]:
ROW = len(box)
COL = len(box[0])
for i in range(ROW):
emptyPos = COL - 1
for j in range(COL - 1, -1, -1):
if box[i][j] == '*':
emptyPos = j - 1
elif box[i][j] == '#':
box[i][j], box[i][emptyPos] = '.', '#'
emptyPos -= 1
rotatedBox = [[''] * ROW for _ in range(COL)]
for i in range(ROW):
for j in range(COL):
rotatedBox[j][ROW - 1 - i] = box[i][j]
return rotatedBox
box = [["#", ".", "#"]]
print(Solution().rotateTheBox(box))
box = [["#", ".", "*", "."],
["#", "#", "*", "."]]
print(Solution().rotateTheBox(box))
box = [["#", "#", "*", ".", "*", "."],
["#", "#", "#", "*", ".", "."],
["#", "#", "#", ".", "#", "."]]
print(Solution().rotateTheBox(box))