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 d3c1f99 commit 3fcbbe1Copy full SHA for 3fcbbe1
rotate-image/Jeehay28.ts
@@ -0,0 +1,26 @@
1
+/**
2
+ Do not return anything, modify matrix in-place instead.
3
+ */
4
+
5
+// TC: O(n^2)
6
+// SC: O(1)
7
+function rotate(matrix: number[][]): void {
8
+ let top = 0;
9
+ let bottom = matrix.length - 1;
10
11
+ while (top < bottom) {
12
+ let left = top;
13
+ let right = bottom;
14
15
+ for (let i = 0; i < bottom - top; i++) {
16
+ const temp = matrix[top][left + i]; // topLeft
17
+ matrix[top][left + i] = matrix[bottom - i][left];
18
+ matrix[bottom - i][left] = matrix[bottom][right - i];
19
+ matrix[bottom][right - i] = matrix[top + i][right];
20
+ matrix[top + i][right] = temp;
21
+ }
22
23
+ top++; // top down
24
+ bottom--; // bottom up
25
26
+}
0 commit comments