Skip to content

Commit a96fe84

Browse files
committed
feat: add typescript solution to lc problem: No.0048.Rotate Image
1 parent 4f1c893 commit a96fe84

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/0000-0099/0048.Rotate Image/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ class Solution {
103103
}
104104
```
105105

106+
### **TypeScript**
107+
108+
```ts
109+
/**
110+
Do not return anything, modify matrix in-place instead.
111+
*/
112+
function rotate(matrix: number[][]): void {
113+
let n = matrix[0].length;
114+
for (let i = 0; i < Math.floor(n / 2); i++) {
115+
for (let j = 0; j < Math.floor((n + 1) / 2); j++) {
116+
let tmp = matrix[i][j];
117+
matrix[i][j] = matrix[n-1-j][i];
118+
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
119+
matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
120+
matrix[j][n - 1 - i] = tmp;
121+
}
122+
}
123+
};
124+
```
125+
106126
### **...**
107127

108128
```

solution/0000-0099/0048.Rotate Image/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ class Solution {
9393
}
9494
```
9595

96+
### **TypeScript**
97+
98+
```ts
99+
/**
100+
Do not return anything, modify matrix in-place instead.
101+
*/
102+
function rotate(matrix: number[][]): void {
103+
let n = matrix[0].length;
104+
for (let i = 0; i < Math.floor(n / 2); i++) {
105+
for (let j = 0; j < Math.floor((n + 1) / 2); j++) {
106+
let tmp = matrix[i][j];
107+
matrix[i][j] = matrix[n-1-j][i];
108+
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
109+
matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
110+
matrix[j][n - 1 - i] = tmp;
111+
}
112+
}
113+
};
114+
```
115+
96116
### **...**
97117

98118
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
Do not return anything, modify matrix in-place instead.
3+
*/
4+
function rotate(matrix: number[][]): void {
5+
let n = matrix[0].length;
6+
for (let i = 0; i < Math.floor(n / 2); i++) {
7+
for (let j = 0; j < Math.floor((n + 1) / 2); j++) {
8+
let tmp = matrix[i][j];
9+
matrix[i][j] = matrix[n-1-j][i];
10+
matrix[n - 1 - j][i] = matrix[n - 1 - i][n - 1 - j];
11+
matrix[n - 1 - i][n - 1 - j] = matrix[j][n - 1 - i];
12+
matrix[j][n - 1 - i] = tmp;
13+
}
14+
}
15+
};

0 commit comments

Comments
 (0)