summaryrefslogtreecommitdiff
path: root/sort-the-matrix-diagonally/src/main.rs
blob: fa8d7e8bde2b38d2323675cbfbbb80b26737aab7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
    }
}