diff --git a/1861. Rotating the Box b/1861. Rotating the Box new file mode 100644 index 0000000..3a21479 --- /dev/null +++ b/1861. Rotating the Box @@ -0,0 +1,40 @@ +class Solution { +public: + void swapChar(vector &vec) + { + int n = vec.size(), Hash = 0; + unordered_mapstore; + for(int i = 0; i < n; i++) + { + Hash += vec[i] == '#'; + if(vec[i] == '*') + store[i] = Hash, Hash = 0; + } + if(Hash) store[n] = Hash; + + for(auto [idx_i, count] : store) + { + int idx = idx_i; + while(count--) vec[--idx] = '#'; + while(idx-- and vec[idx] != '*') vec[idx] = '.'; + } + } + + vector> rotateTheBox(vector>& box) + { + int n = box.size(), m = box[0].size(); + for(auto &Box:box) swapChar(Box); + + vector>box90; + for(int i = m - 1; i >= 0; i--) + { + vectortemp; + for(int j = n - 1; j >= 0; j--) + temp.push_back(box[j][i]); + box90.push_back(temp); + } + + reverse(begin(box90), end(box90)); + return box90; + } +};