1
class Solution {
2
public char[][] rotateTheBox(char[][] box) {
3
int row = box.length, col = box[0].length;
4
char[][] res = new char[col][row];
5
// rotate first, then drop
6
for (int i = 0; i < row; i++) {
7
for (int j = 0; j < col; j++) {
8
res[j][i] = box[row - 1 - i][j];
9
}
10
}
11

12
for (int i = col - 1; i >= 0; i--) {
13
for (int j = 0; j < row; j++) {
14
if (res[i][j] == '#') {
15
int curRow = i;
16
while (curRow + 1 < col && res[curRow + 1][j] == '.') {
17
curRow++;
18
}
19
if (curRow != i) {
20
res[curRow][j] = '#';
21
res[i][j] = '.';
22
}
23
}
24
}
25
}
26
return res;
27
}
28
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0