-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1861-Rotating-the-Box.java
More file actions
35 lines (31 loc) · 960 Bytes
/
1861-Rotating-the-Box.java
File metadata and controls
35 lines (31 loc) · 960 Bytes
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
class Solution {
public char[][] rotateTheBox(char[][] box) {
int m=box.length;
int n=box[0].length;
char[][] rotatedBox=new char[n][m];
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
rotatedBox[i][j] = box[m - 1 - j][i];
}
}
// Iterating from bottom to top
for(int j=0; j<m; j++){//m:Column
int b=n-1, t=n-1;
while(b>=t && t>=0){//n:Row
if(rotatedBox[b][j]=='#'){
b--;
}
else if(rotatedBox[b][j]=='.' && rotatedBox[t][j]=='#'){
rotatedBox[b][j] = rotatedBox[t][j];
rotatedBox[t][j]='.';
b--;
}
else if(rotatedBox[t][j]=='*'){
b=t-1;
}
t--;
}
}
return rotatedBox;
}
}