From 6cf7fce7d50a24e1351376b4e86dd5e6f8d2c8d4 Mon Sep 17 00:00:00 2001 From: xiaolatiao <1628652790@qq.com> Date: Mon, 3 Jul 2023 22:05:24 +0800 Subject: [PATCH] feat: 2643 add rust solution Signed-off-by: xiaolatiao <1628652790@qq.com> --- .../2643.Row With Maximum Ones/README.md | 20 +++++++++++++++++++ .../2643.Row With Maximum Ones/README_EN.md | 20 +++++++++++++++++++ .../2643.Row With Maximum Ones/Solution.rs | 15 ++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 solution/2600-2699/2643.Row With Maximum Ones/Solution.rs diff --git a/solution/2600-2699/2643.Row With Maximum Ones/README.md b/solution/2600-2699/2643.Row With Maximum Ones/README.md index 524d201fbc5ce..2e4ce6434cbc5 100644 --- a/solution/2600-2699/2643.Row With Maximum Ones/README.md +++ b/solution/2600-2699/2643.Row With Maximum Ones/README.md @@ -158,6 +158,26 @@ function rowAndMaximumOnes(mat: number[][]): number[] { } ``` +### **Rust** + +```rust +impl Solution { + pub fn row_and_maximum_ones(mat: Vec>) -> Vec { + let mut ans = vec![0, 0]; + + for (i, row) in mat.iter().enumerate() { + let cnt = row.iter().filter(|&v| *v == 1).count() as i32; + if ans[1] < cnt { + ans[0] = i as i32; + ans[1] = cnt; + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md b/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md index 04097b4fba5bb..4ac5909a2425c 100644 --- a/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md +++ b/solution/2600-2699/2643.Row With Maximum Ones/README_EN.md @@ -143,6 +143,26 @@ function rowAndMaximumOnes(mat: number[][]): number[] { } ``` +### **Rust** + +```rust +impl Solution { + pub fn row_and_maximum_ones(mat: Vec>) -> Vec { + let mut ans = vec![0, 0]; + + for (i, row) in mat.iter().enumerate() { + let cnt = row.iter().filter(|&v| *v == 1).count() as i32; + if ans[1] < cnt { + ans[0] = i as i32; + ans[1] = cnt; + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs b/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs new file mode 100644 index 0000000000000..4ede733da57ca --- /dev/null +++ b/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs @@ -0,0 +1,15 @@ +impl Solution { + pub fn row_and_maximum_ones(mat: Vec>) -> Vec { + let mut ans = vec![0, 0]; + + for (i, row) in mat.iter().enumerate() { + let cnt = row.iter().filter(|&v| *v == 1).count() as i32; + if ans[1] < cnt { + ans[0] = i as i32; + ans[1] = cnt; + } + } + + ans + } +} \ No newline at end of file