File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
solution/0000-0099/0048.Rotate Image Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -103,6 +103,26 @@ class Solution {
103
103
}
104
104
```
105
105
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
+
106
126
### ** ...**
107
127
108
128
```
Original file line number Diff line number Diff line change @@ -93,6 +93,26 @@ class Solution {
93
93
}
94
94
```
95
95
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
+
96
116
### ** ...**
97
117
98
118
```
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments