1030. Matrix Cells in Distance Order Easy
1/**
2 * [1030] Matrix Cells in Distance Order
3 *
4 * You are given four integers row, cols, rCenter, and cCenter. There is a rows x cols matrix and you are on the cell with the coordinates (rCenter, cCenter).
5 * Return the coordinates of all cells in the matrix, sorted by their distance from (rCenter, cCenter) from the smallest distance to the largest distance. You may return the answer in any order that satisfies this condition.
6 * The distance between two cells (r1, c1) and (r2, c2) is |r1 - r2| + |c1 - c2|.
7 *
8 * Example 1:
9 *
10 * Input: rows = 1, cols = 2, rCenter = 0, cCenter = 0
11 * Output: [[0,0],[0,1]]
12 * Explanation: The distances from (0, 0) to other cells are: [0,1]
13 *
14 * Example 2:
15 *
16 * Input: rows = 2, cols = 2, rCenter = 0, cCenter = 1
17 * Output: [[0,1],[0,0],[1,1],[1,0]]
18 * Explanation: The distances from (0, 1) to other cells are: [0,1,1,2]
19 * The answer [[0,1],[1,1],[0,0],[1,0]] would also be accepted as correct.
20 *
21 * Example 3:
22 *
23 * Input: rows = 2, cols = 3, rCenter = 1, cCenter = 2
24 * Output: [[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]]
25 * Explanation: The distances from (1, 2) to other cells are: [0,1,1,2,2,3]
26 * There are other answers that would also be accepted as correct, such as [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]].
27 *
28 *
29 * Constraints:
30 *
31 * 1 <= rows, cols <= 100
32 * 0 <= rCenter < rows
33 * 0 <= cCenter < cols
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/matrix-cells-in-distance-order/
39// discuss: https://leetcode.com/problems/matrix-cells-in-distance-order/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn all_cells_dist_order(rows: i32, cols: i32, r_center: i32, c_center: i32) -> Vec<Vec<i32>> {
45 vec![]
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_1030() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.