Skip to content

Commit 5f3c48e

Browse files
authored
Create 1861. Rotating the Box (#641)
2 parents 5926a5d + 49484c9 commit 5f3c48e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

1861. Rotating the Box

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution {
2+
public:
3+
void swapChar(vector<char> &vec)
4+
{
5+
int n = vec.size(), Hash = 0;
6+
unordered_map<int, int>store;
7+
for(int i = 0; i < n; i++)
8+
{
9+
Hash += vec[i] == '#';
10+
if(vec[i] == '*')
11+
store[i] = Hash, Hash = 0;
12+
}
13+
if(Hash) store[n] = Hash;
14+
15+
for(auto [idx_i, count] : store)
16+
{
17+
int idx = idx_i;
18+
while(count--) vec[--idx] = '#';
19+
while(idx-- and vec[idx] != '*') vec[idx] = '.';
20+
}
21+
}
22+
23+
vector<vector<char>> rotateTheBox(vector<vector<char>>& box)
24+
{
25+
int n = box.size(), m = box[0].size();
26+
for(auto &Box:box) swapChar(Box);
27+
28+
vector<vector<char>>box90;
29+
for(int i = m - 1; i >= 0; i--)
30+
{
31+
vector<char>temp;
32+
for(int j = n - 1; j >= 0; j--)
33+
temp.push_back(box[j][i]);
34+
box90.push_back(temp);
35+
}
36+
37+
reverse(begin(box90), end(box90));
38+
return box90;
39+
}
40+
};

0 commit comments

Comments
 (0)