We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 374b5f9 commit f38e74cCopy full SHA for f38e74c
1861-rotating-the-box/1861-rotating-the-box.java
@@ -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
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