diff options
author | Orangerot <purple@orangerot.dev> | 2024-06-27 11:30:16 +0200 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-06-27 11:30:16 +0200 |
commit | 4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb (patch) | |
tree | 0072cca328fe5adb2ed61004010228ff85e2164d /sort-the-matrix-diagonally/src |
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 + } +} |