Skip to content

Commit b9c02ea

Browse files
committed
feat: add rust solution to lc problem: No.1380
No.1380.Lucky Numbers in a Matrix
1 parent 85ac0df commit b9c02ea

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

solution/1300-1399/1380.Lucky Numbers in a Matrix/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,36 @@ func max(a, b int) int {
167167
}
168168
```
169169

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+
170200
### **...**
171201

172202
```

solution/1300-1399/1380.Lucky Numbers in a Matrix/README_EN.md

+30
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ func max(a, b int) int {
153153
}
154154
```
155155

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+
156186
### **...**
157187

158188
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

0 commit comments

Comments
 (0)