-
-
Notifications
You must be signed in to change notification settings - Fork 9k
/
Copy pathSolution.cpp
29 lines (29 loc) · 888 Bytes
/
Solution.cpp
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
class Solution {
public:
vector<vector<char>> rotateTheBox(vector<vector<char>>& box) {
int m = box.size(), n = box[0].size();
vector<vector<char>> ans(n, vector<char>(m));
for (int i = 0; i < m; ++i) {
for (int j = 0; j < n; ++j) {
ans[j][m - i - 1] = box[i][j];
}
}
for (int j = 0; j < m; ++j) {
queue<int> q;
for (int i = n - 1; ~i; --i) {
if (ans[i][j] == '*') {
queue<int> t;
swap(t, q);
} else if (ans[i][j] == '.') {
q.push(i);
} else if (!q.empty()) {
ans[q.front()][j] = '#';
q.pop();
ans[i][j] = '.';
q.push(i);
}
}
}
return ans;
}
};