- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1861.java
36 lines (35 loc) · 1.23 KB
/
_1861.java
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
packagecom.fishercoder.solutions.secondthousand;
publicclass_1861 {
publicstaticclassSolution1 {
publicchar[][] rotateTheBox(char[][] box) {
intm = box.length;
intn = box[0].length;
for (inti = 0; i < m; i++) {
for (intj = n - 1; j >= 0; j--) {
if (box[i][j] == '#') {
intempty = j + 1;
while (empty < n && box[i][empty] == '.') {
empty++;
}
if (empty < n && box[i][empty] == '.') {
box[i][empty] = '#';
box[i][j] = '.';
} elseif (empty - 1 < n && box[i][empty - 1] == '.') {
box[i][empty - 1] = '#';
box[i][j] = '.';
}
}
}
}
char[][] result = newchar[n][m];
intk = m - 1;
for (inti = 0; i < m; i++) {
for (intj = 0; j < n; j++) {
result[j][k] = box[i][j];
}
k--;
}
returnresult;
}
}
}