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 b795367 commit d1681e1Copy full SHA for d1681e1
javascript/49-Rotate-Image.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {number[][]} matrix
3
+ * @return {void} Do not return anything, modify matrix in-place instead.
4
+ */
5
+var rotate = function(matrix) {
6
+ transpose(matrix);
7
+ reflect(matrix);
8
+};
9
+
10
+var transpose = function(matrix) {
11
+ let n = matrix.length;
12
+ for (let i = 0; i < n; i++) {
13
+ for (let j = i + 1; j < n; j++) {
14
+ let temp = matrix[j][i];
15
+ matrix[j][i] = matrix[i][j];
16
+ matrix[i][j] = temp;
17
+ }
18
19
+}
20
21
+var reflect = function(matrix) {
22
23
24
+ for (let j = 0; j < n / 2; j++) {
25
+ let temp = matrix[i][j];
26
+ matrix[i][j] = matrix[i][n - j - 1];
27
+ matrix[i][n - j - 1] = temp;
28
29
30
0 commit comments