Skip to content

Commit 6480e59

Browse files
committed
add Rotate Image solution
1 parent 1aef08f commit 6480e59

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rotate-image/HoonDongKang.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* [Problem]: [48] Rotate Image
3+
* (https://leetcode.com/problems/rotate-image/)
4+
*/
5+
/**
6+
Do not return anything, modify matrix in-place instead.
7+
*/
8+
// 시간복잡도 O(n^2)
9+
// 공간복잡도 O(1)
10+
function rotate(matrix: number[][]): void {
11+
const length = matrix.length;
12+
13+
for (let i = 0; i < length; i++) {
14+
for (let j = i + 1; j < length; j++) {
15+
[matrix[i][j], matrix[j][i]] = [matrix[j][i], matrix[i][j]];
16+
}
17+
}
18+
19+
for (let i = 0; i < length; i++) {
20+
matrix[i].reverse();
21+
}
22+
}

0 commit comments

Comments
 (0)