Matrix Cells in Distance Order LeetCode solution in Rust
1struct Cell {2r: i32,3c: i32,4d: i32,5}67impl Solution {8pub fn all_cells_dist_order(rows: i32, cols: i32, r_center: i32, c_center: i32) -> Vec<Vec<i32>> {9let mut ret = Vec::new();10let mut cells = Vec::new();11for r in 0..rows {12for c in 0..cols {13let dist = (r_center - r).abs() + (c_center - c).abs();14let cell = Cell {15r: r,16c: c,17d: dist,18};19cells.push(cell);20}21}22cells.sort_by(|a, b| a.d.cmp(&b.d));23for cl in cells {24ret.push(vec![cl.r, cl.c]);25}26ret27}28}