-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1861.cpp
More file actions
37 lines (37 loc) · 1.04 KB
/
1861.cpp
File metadata and controls
37 lines (37 loc) · 1.04 KB
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
37
class Solution {
public:
vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {
int m = box.size();
int n = box[0].size();
for (int i = 0; i < m; ++i) {
int cnt = 0;
for (int j = 0; j < n; ++j) {
if (box[i][j] == '#') {
box[i][j] = '.';
cnt++;
}
else if (box[i][j] == '*') {
int curr = j - 1;
while (cnt > 0) {
box[i][curr] = '#';
curr--;
cnt--;
}
}
}
int curr = n - 1;
while (cnt > 0) {
box[i][curr] = '#';
curr--;
cnt--;
}
}
vector<vector<char>> res(n, vector<char>(m, '.'));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
res[j][i] = box[m - i - 1][j];
}
}
return res;
}
};