885. Spiral Matrix III Medium
1/**
2 * [885] Spiral Matrix III
3 *
4 * You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column.
5 * You will walk in a clockwise spiral shape to visit every position in this grid. Whenever you move outside the grid's boundary, we continue our walk outside the grid (but may return to the grid boundary later.). Eventually, we reach all rows * cols spaces of the grid.
6 * Return an array of coordinates representing the positions of the grid in the order you visited them.
7 *
8 * Example 1:
9 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/24/example_1.png" style="width: 174px; height: 99px;" />
10 * Input: rows = 1, cols = 4, rStart = 0, cStart = 0
11 * Output: [[0,0],[0,1],[0,2],[0,3]]
12 *
13 * Example 2:
14 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/24/example_2.png" style="width: 202px; height: 142px;" />
15 * Input: rows = 5, cols = 6, rStart = 1, cStart = 4
16 * Output: [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,2],[4,1],[3,1],[2,1],[1,1],[0,1],[4,0],[3,0],[2,0],[1,0],[0,0]]
17 *
18 *
19 * Constraints:
20 *
21 * 1 <= rows, cols <= 100
22 * 0 <= rStart < rows
23 * 0 <= cStart < cols
24 *
25 */
26pub struct Solution {}
27
28// problem: https://leetcode.com/problems/spiral-matrix-iii/
29// discuss: https://leetcode.com/problems/spiral-matrix-iii/discuss/?currentPage=1&orderBy=most_votes&query=
30
31// submission codes start here
32
33impl Solution {
34 pub fn spiral_matrix_iii(rows: i32, cols: i32, r_start: i32, c_start: i32) -> Vec<Vec<i32>> {
35 vec![]
36 }
37}
38
39// submission codes end
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[test]
46 fn test_885() {
47 }
48}
49
Back
© 2025 bowen.ge All Rights Reserved.