Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5284f9f

Browse files
authored
refactor: update solution to lc problem: No.1091 (doocs#2910)
1 parent 44a6967 commit 5284f9f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

‎solution/1000-1099/1091.Shortest Path in Binary Matrix/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,18 @@ function shortestPathBinaryMatrix(grid: number[][]): number {
220220
if (grid[0][0]) {
221221
return -1;
222222
}
223-
const n = grid.length;
223+
const max = grid.length-1;
224224
grid[0][0] = 1;
225225
let q: number[][] = [[0, 0]];
226226
for (let ans = 1; q.length > 0; ++ans) {
227227
const nq: number[][] = [];
228228
for (const [i, j] of q) {
229-
if (i === n-1&& j === n-1) {
229+
if (i === max&& j === max) {
230230
return ans;
231231
}
232232
for (let x = i - 1; x <= i + 1; ++x) {
233233
for (let y = j - 1; y <= j + 1; ++y) {
234-
if (x>=0&&x<n&&y>=0&&y<n&&!grid[x][y]) {
234+
if (grid[x]?.[y]===0) {
235235
grid[x][y] = 1;
236236
nq.push([x, y]);
237237
}

‎solution/1000-1099/1091.Shortest Path in Binary Matrix/README_EN.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,18 +206,18 @@ function shortestPathBinaryMatrix(grid: number[][]): number {
206206
if (grid[0][0]) {
207207
return -1;
208208
}
209-
const n = grid.length;
209+
const max = grid.length-1;
210210
grid[0][0] = 1;
211211
let q: number[][] = [[0, 0]];
212212
for (let ans = 1; q.length > 0; ++ans) {
213213
const nq: number[][] = [];
214214
for (const [i, j] of q) {
215-
if (i === n-1&& j === n-1) {
215+
if (i === max&& j === max) {
216216
return ans;
217217
}
218218
for (let x = i - 1; x <= i + 1; ++x) {
219219
for (let y = j - 1; y <= j + 1; ++y) {
220-
if (x>=0&&x<n&&y>=0&&y<n&&!grid[x][y]) {
220+
if (grid[x]?.[y]===0) {
221221
grid[x][y] = 1;
222222
nq.push([x, y]);
223223
}

‎solution/1000-1099/1091.Shortest Path in Binary Matrix/Solution.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ function shortestPathBinaryMatrix(grid: number[][]): number {
22
if (grid[0][0]) {
33
return -1;
44
}
5-
const n = grid.length;
5+
const max = grid.length-1;
66
grid[0][0] = 1;
77
let q: number[][] = [[0, 0]];
88
for (let ans = 1; q.length > 0; ++ans) {
99
const nq: number[][] = [];
1010
for (const [i, j] of q) {
11-
if (i === n-1&& j === n-1) {
11+
if (i === max&& j === max) {
1212
return ans;
1313
}
1414
for (let x = i - 1; x <= i + 1; ++x) {
1515
for (let y = j - 1; y <= j + 1; ++y) {
16-
if (x>=0&&x<n&&y>=0&&y<n&&!grid[x][y]) {
16+
if (grid[x]?.[y]===0) {
1717
grid[x][y] = 1;
1818
nq.push([x, y]);
1919
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /