transpose-matrix

This commit is contained in:
Gleb Koval 2022-06-02 23:44:15 +01:00
parent 17e37c823d
commit 0a8bf37562
Signed by: cyclane
GPG Key ID: 15E168A8B332382C
1 changed files with 12 additions and 0 deletions

12
transpose-matrix/sol.rs Normal file
View File

@ -0,0 +1,12 @@
impl Solution {
pub fn transpose(matrix: Vec<Vec<i32>>) -> Vec<Vec<i32>> {
let n = matrix[0].len();
(0..n).into_iter()
.map(|i| matrix
.iter()
.map(|row| row[i])
.collect()
)
.collect()
}
}