summaryrefslogtreecommitdiff
path: root/sort-the-matrix-diagonally
diff options
context:
space:
mode:
authorOrangerot <purple@orangerot.dev>2024-06-27 11:30:16 +0200
committerOrangerot <purple@orangerot.dev>2024-06-27 11:30:16 +0200
commit4b0a6a01b051a4ebfbc17661d14cb23fe4f275fb (patch)
tree0072cca328fe5adb2ed61004010228ff85e2164d /sort-the-matrix-diagonally
Initial commitHEADmain
Diffstat (limited to 'sort-the-matrix-diagonally')
-rw-r--r--sort-the-matrix-diagonally/Cargo.toml8
-rw-r--r--sort-the-matrix-diagonally/src/main.rs26
2 files changed, 34 insertions, 0 deletions
diff --git a/sort-the-matrix-diagonally/Cargo.toml b/sort-the-matrix-diagonally/Cargo.toml
new file mode 100644
index 0000000..8e05371
--- /dev/null
+++ b/sort-the-matrix-diagonally/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "sort-the-matrix-diagonally"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
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
+ }
+}