Skip to content

Commit a759f9c

Browse files
authored
Update Solution.js
1 parent 25caf40 commit a759f9c

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

solution/0800-0899/0885.Spiral Matrix III/Solution.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,30 @@
66
* @return {number[][]}
77
*/
88
var spiralMatrixIII = function (rows, cols, rStart, cStart) {
9-
let result = [];
10-
let totalCells = rows * cols;
11-
let directions = [
9+
const ans = [];
10+
const totalCells = rows * cols;
11+
const directions = [
1212
[0, 1],
1313
[1, 0],
1414
[0, -1],
1515
[-1, 0],
1616
];
1717
let step = 0;
1818
let d = 0;
19-
let r = rStart,
20-
c = cStart;
21-
22-
result.push([r, c]);
23-
24-
while (result.length < totalCells) {
25-
if (d === 0 || d === 2) step++;
26-
19+
let [r, c] = [rStart, cStart];
20+
ans.push([r, c]);
21+
while (ans.length < totalCells) {
22+
if (d === 0 || d === 2) {
23+
step++;
24+
}
2725
for (let i = 0; i < step; i++) {
2826
r += directions[d][0];
2927
c += directions[d][1];
30-
3128
if (r >= 0 && r < rows && c >= 0 && c < cols) {
32-
result.push([r, c]);
29+
ans.push([r, c]);
3330
}
3431
}
35-
3632
d = (d + 1) % 4;
3733
}
38-
39-
return result;
34+
return ans;
4035
};

0 commit comments

Comments
 (0)