From cb095b903140aeac1fd7d700c0137b749ed1c028 Mon Sep 17 00:00:00 2001 From: xiaolatiao <1628652790@qq.com> Date: Tue, 4 Jul 2023 21:02:47 +0800 Subject: [PATCH] feat: 2639 add rust solution Signed-off-by: xiaolatiao <1628652790@qq.com> --- .../README.md | 19 +++++++++++++++++++ .../README_EN.md | 19 +++++++++++++++++++ .../Solution.rs | 14 ++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 solution/2600-2699/2639.Find the Width of Columns of a Grid/Solution.rs diff --git a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md index 8f22f896173a6..05353abbf0f41 100644 --- a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md +++ b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README.md @@ -160,6 +160,25 @@ function findColumnWidth(grid: number[][]): number[] { } ``` +### **Rust** + +```rust +impl Solution { + pub fn find_column_width(grid: Vec>) -> Vec { + let mut ans = vec![0; grid[0].len()]; + + for row in grid.iter() { + for (j, num) in row.iter().enumerate() { + let width = num.to_string().len() as i32; + ans[j] = std::cmp::max(ans[j], width); + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md index 2abaaced6cc22..b81f443eb63c5 100644 --- a/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md +++ b/solution/2600-2699/2639.Find the Width of Columns of a Grid/README_EN.md @@ -142,6 +142,25 @@ function findColumnWidth(grid: number[][]): number[] { } ``` +### **Rust** + +```rust +impl Solution { + pub fn find_column_width(grid: Vec>) -> Vec { + let mut ans = vec![0; grid[0].len()]; + + for row in grid.iter() { + for (j, num) in row.iter().enumerate() { + let width = num.to_string().len() as i32; + ans[j] = std::cmp::max(ans[j], width); + } + } + + ans + } +} +``` + ### **...** ``` diff --git a/solution/2600-2699/2639.Find the Width of Columns of a Grid/Solution.rs b/solution/2600-2699/2639.Find the Width of Columns of a Grid/Solution.rs new file mode 100644 index 0000000000000..74ee6c03c449e --- /dev/null +++ b/solution/2600-2699/2639.Find the Width of Columns of a Grid/Solution.rs @@ -0,0 +1,14 @@ +impl Solution { + pub fn find_column_width(grid: Vec>) -> Vec { + let mut ans = vec![0; grid[0].len()]; + + for row in grid.iter() { + for (j, num) in row.iter().enumerate() { + let width = num.to_string().len() as i32; + ans[j] = std::cmp::max(ans[j], width); + } + } + + ans + } +} \ No newline at end of file