Skip to content

Commit 4c07d50

Browse files
authored
Create Solution.js
1 parent e48cc32 commit 4c07d50

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
q.push(i);
27+
}
28+
}
29+
}
30+
31+
return ans;
32+
};

0 commit comments

Comments
 (0)