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 606da9c commit aa650bbCopy full SHA for aa650bb
rotate-image/HC-kang.ts
@@ -0,0 +1,22 @@
1
+/**
2
+ * https://leetcode.com/problems/rotate-image
3
+ * T.C. O(n^2)
4
+ * S.C. O(1)
5
+ */
6
+function rotate(matrix: number[][]): void {
7
+ const n = matrix.length;
8
+
9
+ // transpose
10
+ for (let i = 0; i < n; i++) {
11
+ for (let j = i; j < n; j++) {
12
+ [matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
13
+ }
14
15
16
+ // reverse
17
18
+ for (let j = 0; j < n / 2; j++) {
19
+ [matrix[i][j], matrix[i][n - j - 1]] = [matrix[i][n - j - 1], matrix[i][j]];
20
21
22
+}
0 commit comments