From 47342b20b6ebf83d24df73adb374bfeecf78e8f9 Mon Sep 17 00:00:00 2001 From: xiaolatiao <1628652790@qq.com> Date: Tue, 25 Jul 2023 20:30:35 +0800 Subject: [PATCH] feat: add rust solution to lc problem: No.2500 Signed-off-by: xiaolatiao <1628652790@qq.com> --- .../README.md | 28 +++++++++++++++++++ .../README_EN.md | 28 +++++++++++++++++++ .../Solution.rs | 23 +++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 solution/2500-2599/2500.Delete Greatest Value in Each Row/Solution.rs 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