diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md index d2edffb8742f6..8c2a45adb86ea 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README.md @@ -147,6 +147,34 @@ func deleteGreatestValue(grid [][]int) (ans int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn delete_greatest_value(grid: Vec>) -> i32 { + let mut grid = grid; + for i in 0..grid.len() { + grid[i].sort(); + } + + let mut ans = 0; + for j in 0..grid[0].len() { + let mut mx = 0; + + for i in 0..grid.len() { + if grid[i][j] > mx { + mx = grid[i][j]; + } + } + + ans += mx; + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md index e57a9fce51a0d..4814010e5addf 100644 --- a/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/README_EN.md @@ -125,6 +125,34 @@ func deleteGreatestValue(grid [][]int) (ans int) { } ``` +### **Rust** + +```rust +impl Solution { + pub fn delete_greatest_value(grid: Vec>) -> i32 { + let mut grid = grid; + for i in 0..grid.len() { + grid[i].sort(); + } + + let mut ans = 0; + for j in 0..grid[0].len() { + let mut mx = 0; + + for i in 0..grid.len() { + if grid[i][j] > mx { + mx = grid[i][j]; + } + } + + ans += mx; + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.rs b/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.rs new file mode 100644 index 0000000000000..ba6094986e047 --- /dev/null +++ b/solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.rs @@ -0,0 +1,23 @@ +impl Solution { + pub fn delete_greatest_value(grid: Vec>) -> i32 { + let mut grid = grid; + for i in 0..grid.len() { + grid[i].sort(); + } + + let mut ans = 0; + for j in 0..grid[0].len() { + let mut mx = 0; + + for i in 0..grid.len() { + if grid[i][j] > mx { + mx = grid[i][j]; + } + } + + ans += mx; + } + + ans + } +} \ No newline at end of file