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