Skip to content

Commit e789bd1

Browse files
authored
feat: add rust solution to lc problem: No.2500 (#1299)
Signed-off-by: xiaolatiao <1628652790@qq.com>
1 parent 166ec20 commit e789bd1

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ func deleteGreatestValue(grid [][]int) (ans int) {
147147
}
148148
```
149149

150+
### **Rust**
151+
152+
```rust
153+
impl Solution {
154+
pub fn delete_greatest_value(grid: Vec<Vec<i32>>) -> i32 {
155+
let mut grid = grid;
156+
for i in 0..grid.len() {
157+
grid[i].sort();
158+
}
159+
160+
let mut ans = 0;
161+
for j in 0..grid[0].len() {
162+
let mut mx = 0;
163+
164+
for i in 0..grid.len() {
165+
if grid[i][j] > mx {
166+
mx = grid[i][j];
167+
}
168+
}
169+
170+
ans += mx;
171+
}
172+
173+
ans
174+
}
175+
}
176+
```
177+
150178
### **...**
151179

152180
```

solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md

+28
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,34 @@ func deleteGreatestValue(grid [][]int) (ans int) {
125125
}
126126
```
127127

128+
### **Rust**
129+
130+
```rust
131+
impl Solution {
132+
pub fn delete_greatest_value(grid: Vec<Vec<i32>>) -> i32 {
133+
let mut grid = grid;
134+
for i in 0..grid.len() {
135+
grid[i].sort();
136+
}
137+
138+
let mut ans = 0;
139+
for j in 0..grid[0].len() {
140+
let mut mx = 0;
141+
142+
for i in 0..grid.len() {
143+
if grid[i][j] > mx {
144+
mx = grid[i][j];
145+
}
146+
}
147+
148+
ans += mx;
149+
}
150+
151+
ans
152+
}
153+
}
154+
```
155+
128156
### **...**
129157

130158
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
impl Solution {
2+
pub fn delete_greatest_value(grid: Vec<Vec<i32>>) -> i32 {
3+
let mut grid = grid;
4+
for i in 0..grid.len() {
5+
grid[i].sort();
6+
}
7+
8+
let mut ans = 0;
9+
for j in 0..grid[0].len() {
10+
let mut mx = 0;
11+
12+
for i in 0..grid.len() {
13+
if grid[i][j] > mx {
14+
mx = grid[i][j];
15+
}
16+
}
17+
18+
ans += mx;
19+
}
20+
21+
ans
22+
}
23+
}

0 commit comments

Comments
 (0)