Skip to content

Commit 3a1081f

Browse files
refactor 885
1 parent 5f720f2 commit 3a1081f

File tree

1 file changed

+3
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+3
-25
lines changed

src/main/java/com/fishercoder/solutions/_885.java

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 885. Spiral Matrix III
5-
*
6-
* On a 2 dimensional grid with R rows and C columns, we start at (r0, c0) facing east.
7-
* Here, the north-west corner of the grid is at the first row and column, and the south-east corner of the grid is at the last row and column.
8-
* Now, we walk in a clockwise spiral shape to visit every position in this grid.
9-
* Whenever we would move outside the boundary of the grid, we continue our walk outside the grid (but may return to the grid boundary later.)
10-
* Eventually, we reach all R * C spaces of the grid.
11-
* Return a list of coordinates representing the positions of the grid in the order they were visited.
12-
*
13-
* Example 1:
14-
* Input: R = 1, C = 4, r0 = 0, c0 = 0
15-
* Output: [[0,0],[0,1],[0,2],[0,3]]
16-
*
17-
* Example 2:
18-
* Input: R = 5, C = 6, r0 = 1, c0 = 4
19-
* 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]]
20-
*
21-
* Note:
22-
* 1 <= R <= 100
23-
* 1 <= C <= 100
24-
* 0 <= r0 < R
25-
* 0 <= c0 < C
26-
* */
273
public class _885 {
284
public static class Solution1 {
29-
/**credit: https://leetcode.com/problems/spiral-matrix-iii/discuss/158977/Java-15-lines-concise-solution-with-comments*/
5+
/**
6+
* credit: https://leetcode.com/problems/spiral-matrix-iii/discuss/158977/Java-15-lines-concise-solution-with-comments
7+
*/
308
public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {
319
int[] directions = new int[]{0, 1, 0, -1, 0};
3210
int[][] result = new int[R * C][2];

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy