diff options
Diffstat (limited to 'sort-the-matrix-diagonally/src')
-rw-r--r-- | sort-the-matrix-diagonally/src/main.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/sort-the-matrix-diagonally/src/main.rs b/sort-the-matrix-diagonally/src/main.rs new file mode 100644 index 0000000..fa8d7e8 --- /dev/null +++ b/sort-the-matrix-diagonally/src/main.rs @@ -0,0 +1,26 @@ +fn main() { + println!("Hello, world!"); +} + +struct Solution; + +use std::collections::HashMap; + +impl Solution { + pub fn diagonal_sort(mut mat: Vec<Vec<i32>>) -> Vec<Vec<i32>> { + let mut a = HashMap::new(); + + for (i, row) in mat.iter().enumerate() { + for (ii, value) in row.iter().enumerate() { + a.entry(i-ii).and_modify(|x: &mut Vec<&i32>| {x.push(value)}).or_insert(vec![value]); + } + } + + for i in a.values_mut() { + i.sort(); + println!("{i:?}"); + } + + mat + } +} |