File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
solution/1300-1399/1380.Lucky Numbers in a Matrix Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -167,6 +167,34 @@ func max(a, b int) int {
167
167
}
168
168
```
169
169
170
+ ### ** TypeScript**
171
+
172
+ ``` ts
173
+ function luckyNumbers(matrix : number [][]): number [] {
174
+ const m = matrix .length ;
175
+ const n = matrix [0 ].length ;
176
+ const col = new Array (n ).fill (0 );
177
+ const res = [];
178
+ for (let j = 0 ; j < n ; j ++ ) {
179
+ for (let i = 0 ; i < m ; i ++ ) {
180
+ col [j ] = Math .max (col [j ], matrix [i ][j ]);
181
+ }
182
+ }
183
+ for (let x = 0 ; x < m ; x ++ ) {
184
+ let i = 0 ;
185
+ for (let y = 1 ; y < n ; y ++ ) {
186
+ if (matrix [x ][i ] > matrix [x ][y ]) {
187
+ i = y ;
188
+ }
189
+ }
190
+ if (matrix [x ][i ] === col [i ]) {
191
+ res .push (col [i ]);
192
+ }
193
+ }
194
+ return res ;
195
+ }
196
+ ```
197
+
170
198
### ** Rust**
171
199
172
200
``` rust
Original file line number Diff line number Diff line change @@ -153,6 +153,34 @@ func max(a, b int) int {
153
153
}
154
154
```
155
155
156
+ ### ** TypeScript**
157
+
158
+ ``` ts
159
+ function luckyNumbers(matrix : number [][]): number [] {
160
+ const m = matrix .length ;
161
+ const n = matrix [0 ].length ;
162
+ const col = new Array (n ).fill (0 );
163
+ const res = [];
164
+ for (let j = 0 ; j < n ; j ++ ) {
165
+ for (let i = 0 ; i < m ; i ++ ) {
166
+ col [j ] = Math .max (col [j ], matrix [i ][j ]);
167
+ }
168
+ }
169
+ for (let x = 0 ; x < m ; x ++ ) {
170
+ let i = 0 ;
171
+ for (let y = 1 ; y < n ; y ++ ) {
172
+ if (matrix [x ][i ] > matrix [x ][y ]) {
173
+ i = y ;
174
+ }
175
+ }
176
+ if (matrix [x ][i ] === col [i ]) {
177
+ res .push (col [i ]);
178
+ }
179
+ }
180
+ return res ;
181
+ }
182
+ ```
183
+
156
184
### ** Rust**
157
185
158
186
``` rust
Original file line number Diff line number Diff line change
1
+ function luckyNumbers ( matrix : number [ ] [ ] ) : number [ ] {
2
+ const m = matrix . length ;
3
+ const n = matrix [ 0 ] . length ;
4
+ const col = new Array ( n ) . fill ( 0 ) ;
5
+ const res = [ ] ;
6
+ for ( let j = 0 ; j < n ; j ++ ) {
7
+ for ( let i = 0 ; i < m ; i ++ ) {
8
+ col [ j ] = Math . max ( col [ j ] , matrix [ i ] [ j ] ) ;
9
+ }
10
+ }
11
+ for ( let x = 0 ; x < m ; x ++ ) {
12
+ let i = 0 ;
13
+ for ( let y = 1 ; y < n ; y ++ ) {
14
+ if ( matrix [ x ] [ i ] > matrix [ x ] [ y ] ) {
15
+ i = y ;
16
+ }
17
+ }
18
+ if ( matrix [ x ] [ i ] === col [ i ] ) {
19
+ res . push ( col [ i ] ) ;
20
+ }
21
+ }
22
+ return res ;
23
+ }
You can’t perform that action at this time.
0 commit comments