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