Skip to content

Commit 7edc4bd

Browse files
update 885
1 parent b8c6009 commit 7edc4bd

File tree

1 file changed

+8
-8
lines changed
  • src/main/java/com/fishercoder/solutions/firstthousand

1 file changed

+8
-8
lines changed

Diff for: src/main/java/com/fishercoder/solutions/firstthousand/_885.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ public static class Solution1 {
55
/**
66
* credit: https://leetcode.com/problems/spiral-matrix-iii/discuss/158977/Java-15-lines-concise-solution-with-comments
77
*/
8-
public int[][] spiralMatrixIII(int R, int C, int r0, int c0) {
8+
public int[][] spiralMatrixIII(int rows, int cols, int rStart, int cStart) {
99
int[] directions = new int[]{0, 1, 0, -1, 0};
10-
int[][] result = new int[R * C][2];
10+
int[][] result = new int[rows * cols][2];
1111
int i = 0;
12-
result[i++] = new int[]{r0, c0};
12+
result[i++] = new int[]{rStart, cStart};
1313
int len = 0;
1414
int d = 0;
15-
while (i < R * C) {
15+
while (i < rows * cols) {
1616
if (d == 0 || d == 2) {
1717
//plus one when moving east or west
1818
len++;
1919
}
2020
for (int k = 0; k < len; k++) {
21-
r0 += directions[d];
22-
c0 += directions[d + 1];
23-
if (r0 >= 0 && r0 < R && c0 >= 0 && c0 < C) {
24-
result[i++] = new int[]{r0, c0};
21+
rStart += directions[d];
22+
cStart += directions[d + 1];
23+
if (rStart >= 0 && rStart < rows && cStart >= 0 && cStart < cols) {
24+
result[i++] = new int[]{rStart, cStart};
2525
}
2626
}
2727
d = (d + 1) % 4;

0 commit comments

Comments
 (0)