Skip to content

Commit f38e74c

Browse files
committed
Time: 8 ms (68.29%), Space: 79.5 MB (59.61%) - LeetHub
1 parent 374b5f9 commit f38e74c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class Solution {
2+
public char[][] rotateTheBox(char[][] box) {
3+
int m = box.length;
4+
int n = box[0].length;
5+
6+
// 1.Rotate
7+
// 2. Gravity fall
8+
9+
char[][] res = new char[n][m];
10+
11+
//rotate
12+
for(int i=0;i<m;i++){
13+
for(int j=0;j<n;j++){
14+
res[j][i] = box[m-1-i][j];
15+
}
16+
}
17+
18+
//gravity fall :
19+
for(int i=0;i<m;i++){
20+
int last = n-1;
21+
for(int j=n-1;j>=0;j--){
22+
char ch = res[j][i];
23+
if(ch=='.') continue;
24+
if(ch=='#'){
25+
res[j][i] = '.';
26+
res[last][i]='#';
27+
last--;
28+
}
29+
if(ch=='*') last =j-1;
30+
31+
}
32+
}
33+
return res;
34+
}
35+
}

0 commit comments

Comments
 (0)