We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e48cc32 commit 4c07d50Copy full SHA for 4c07d50
solution/1800-1899/1861.Rotating the Box/Solution.js
@@ -0,0 +1,32 @@
1
+/**
2
+ * @param {character[][]} box
3
+ * @return {character[][]}
4
+ */
5
+var rotateTheBox = function(box) {
6
+ const m = box.length;
7
+ const n = box[0].length;
8
+ const ans = Array.from({ length: n }, () => Array(m).fill(null));
9
+
10
+ for (let i = 0; i < m; i++) {
11
+ for (let j = 0; j < n; j++) {
12
+ ans[j][m - i - 1] = box[i][j];
13
+ }
14
15
16
+ for (let j = 0; j < m; j++) {
17
+ const q = [];
18
+ for (let i = n - 1; i >= 0; i--) {
19
+ if (ans[i][j] === '*') {
20
+ q.length = 0;
21
+ } else if (ans[i][j] === '.') {
22
+ q.push(i);
23
+ } else if (q.length > 0) {
24
+ ans[q.shift()][j] = '#';
25
+ ans[i][j] = '.';
26
27
28
29
30
31
+ return ans;
32
+};
0 commit comments