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 b124017

Browse files
fix: update solutions to lc problems: No.3341,3342 (#4391)
1 parent c34a0d2 commit b124017

File tree

6 files changed

+81
-81
lines changed

6 files changed

+81
-81
lines changed

‎solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,31 +271,31 @@ func (h *hp) Pop() (v any) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; re
271271

272272
```ts
273273
function minTimeToReach(moveTime: number[][]): number {
274-
const [n, m] = [moveTime.length, moveTime[0].length];
275-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
274+
const n = moveTime.length;
275+
const m = moveTime[0].length;
276+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
276277
dist[0][0] = 0;
277-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
278+
type Node = [number, number, number];
279+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
278280
pq.enqueue([0, 0, 0]);
279281
const dirs = [-1, 0, 1, 0, -1];
280-
while (1) {
282+
while (!pq.isEmpty()) {
281283
const [d, i, j] = pq.dequeue();
282-
if (i === n - 1 && j === m - 1) {
283-
return d;
284-
}
285-
if (d > dist[i][j]) {
286-
continue;
287-
}
284+
if (d > dist[i][j]) continue;
285+
if (i === n - 1 && j === m - 1) return d;
288286
for (let k = 0; k < 4; ++k) {
289-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
287+
const x = i + dirs[k];
288+
const y = j + dirs[k + 1];
290289
if (x >= 0 && x < n && y >= 0 && y < m) {
291-
const t = Math.max(moveTime[x][y], dist[i][j]) + 1;
292-
if (dist[x][y]>t) {
290+
const t = Math.max(moveTime[x][y], d) + 1;
291+
if (t<dist[x][y]) {
293292
dist[x][y] = t;
294293
pq.enqueue([t, x, y]);
295294
}
296295
}
297296
}
298297
}
298+
return -1;
299299
}
300300
```
301301

‎solution/3300-3399/3341.Find Minimum Time to Reach Last Room I/README_EN.md‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -268,31 +268,31 @@ func (h *hp) Pop() (v any) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; re
268268

269269
```ts
270270
function minTimeToReach(moveTime: number[][]): number {
271-
const [n, m] = [moveTime.length, moveTime[0].length];
272-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
271+
const n = moveTime.length;
272+
const m = moveTime[0].length;
273+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
273274
dist[0][0] = 0;
274-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
275+
type Node = [number, number, number];
276+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
275277
pq.enqueue([0, 0, 0]);
276278
const dirs = [-1, 0, 1, 0, -1];
277-
while (1) {
279+
while (!pq.isEmpty()) {
278280
const [d, i, j] = pq.dequeue();
279-
if (i === n - 1 && j === m - 1) {
280-
return d;
281-
}
282-
if (d > dist[i][j]) {
283-
continue;
284-
}
281+
if (d > dist[i][j]) continue;
282+
if (i === n - 1 && j === m - 1) return d;
285283
for (let k = 0; k < 4; ++k) {
286-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
284+
const x = i + dirs[k];
285+
const y = j + dirs[k + 1];
287286
if (x >= 0 && x < n && y >= 0 && y < m) {
288-
const t = Math.max(moveTime[x][y], dist[i][j]) + 1;
289-
if (dist[x][y]>t) {
287+
const t = Math.max(moveTime[x][y], d) + 1;
288+
if (t<dist[x][y]) {
290289
dist[x][y] = t;
291290
pq.enqueue([t, x, y]);
292291
}
293292
}
294293
}
295294
}
295+
return -1;
296296
}
297297
```
298298

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
function minTimeToReach(moveTime: number[][]): number {
2-
const [n, m] = [moveTime.length, moveTime[0].length];
3-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
2+
const n = moveTime.length;
3+
const m = moveTime[0].length;
4+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
45
dist[0][0] = 0;
5-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
6+
type Node = [number, number, number];
7+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
68
pq.enqueue([0, 0, 0]);
79
const dirs = [-1, 0, 1, 0, -1];
8-
while (1) {
10+
while (!pq.isEmpty()) {
911
const [d, i, j] = pq.dequeue();
10-
if (i === n - 1 && j === m - 1) {
11-
return d;
12-
}
13-
if (d > dist[i][j]) {
14-
continue;
15-
}
12+
if (d > dist[i][j]) continue;
13+
if (i === n - 1 && j === m - 1) return d;
1614
for (let k = 0; k < 4; ++k) {
17-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
15+
const x = i + dirs[k];
16+
const y = j + dirs[k + 1];
1817
if (x >= 0 && x < n && y >= 0 && y < m) {
19-
const t = Math.max(moveTime[x][y], dist[i][j]) + 1;
20-
if (dist[x][y]>t) {
18+
const t = Math.max(moveTime[x][y], d) + 1;
19+
if (t<dist[x][y]) {
2120
dist[x][y] = t;
2221
pq.enqueue([t, x, y]);
2322
}
2423
}
2524
}
2625
}
26+
return -1;
2727
}

‎solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -272,31 +272,31 @@ func (h *hp) Pop() (v any) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; re
272272

273273
```ts
274274
function minTimeToReach(moveTime: number[][]): number {
275-
const [n, m] = [moveTime.length, moveTime[0].length];
276-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
275+
const n = moveTime.length;
276+
const m = moveTime[0].length;
277+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
277278
dist[0][0] = 0;
278-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
279+
type Node = [number, number, number];
280+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
279281
pq.enqueue([0, 0, 0]);
280282
const dirs = [-1, 0, 1, 0, -1];
281-
while (1) {
283+
while (!pq.isEmpty()) {
282284
const [d, i, j] = pq.dequeue();
283-
if (i === n - 1 && j === m - 1) {
284-
return d;
285-
}
286-
if (d > dist[i][j]) {
287-
continue;
288-
}
289-
for (let k = 0; k < 4; ++k) {
290-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
285+
if (d > dist[i][j]) continue;
286+
if (i === n - 1 && j === m - 1) return d;
287+
for (let k = 0; k < 4; k++) {
288+
const x = i + dirs[k];
289+
const y = j + dirs[k + 1];
291290
if (x >= 0 && x < n && y >= 0 && y < m) {
292-
const t = Math.max(moveTime[x][y], dist[i][j]) + ((i + j) % 2) + 1;
293-
if (dist[x][y]>t) {
291+
const t = Math.max(moveTime[x][y], d) + ((i + j) % 2) + 1;
292+
if (t<dist[x][y]) {
294293
dist[x][y] = t;
295294
pq.enqueue([t, x, y]);
296295
}
297296
}
298297
}
299298
}
299+
return -1;
300300
}
301301
```
302302

‎solution/3300-3399/3342.Find Minimum Time to Reach Last Room II/README_EN.md‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,31 +269,31 @@ func (h *hp) Pop() (v any) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; re
269269

270270
```ts
271271
function minTimeToReach(moveTime: number[][]): number {
272-
const [n, m] = [moveTime.length, moveTime[0].length];
273-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
272+
const n = moveTime.length;
273+
const m = moveTime[0].length;
274+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
274275
dist[0][0] = 0;
275-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
276+
type Node = [number, number, number];
277+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
276278
pq.enqueue([0, 0, 0]);
277279
const dirs = [-1, 0, 1, 0, -1];
278-
while (1) {
280+
while (!pq.isEmpty()) {
279281
const [d, i, j] = pq.dequeue();
280-
if (i === n - 1 && j === m - 1) {
281-
return d;
282-
}
283-
if (d > dist[i][j]) {
284-
continue;
285-
}
286-
for (let k = 0; k < 4; ++k) {
287-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
282+
if (d > dist[i][j]) continue;
283+
if (i === n - 1 && j === m - 1) return d;
284+
for (let k = 0; k < 4; k++) {
285+
const x = i + dirs[k];
286+
const y = j + dirs[k + 1];
288287
if (x >= 0 && x < n && y >= 0 && y < m) {
289-
const t = Math.max(moveTime[x][y], dist[i][j]) + ((i + j) % 2) + 1;
290-
if (dist[x][y]>t) {
288+
const t = Math.max(moveTime[x][y], d) + ((i + j) % 2) + 1;
289+
if (t<dist[x][y]) {
291290
dist[x][y] = t;
292291
pq.enqueue([t, x, y]);
293292
}
294293
}
295294
}
296295
}
296+
return -1;
297297
}
298298
```
299299

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
function minTimeToReach(moveTime: number[][]): number {
2-
const [n, m] = [moveTime.length, moveTime[0].length];
3-
const dist: number[][] = Array.from({ length: n }, () => Array(m).fill(Infinity));
2+
const n = moveTime.length;
3+
const m = moveTime[0].length;
4+
const dist = Array.from({ length: n }, () => Array(m).fill(Infinity));
45
dist[0][0] = 0;
5-
const pq = new PriorityQueue({ compare: (a, b) => a[0] - b[0] });
6+
type Node = [number, number, number];
7+
const pq = new PriorityQueue<Node>((a, b) => a[0] - b[0]);
68
pq.enqueue([0, 0, 0]);
79
const dirs = [-1, 0, 1, 0, -1];
8-
while (1) {
10+
while (!pq.isEmpty()) {
911
const [d, i, j] = pq.dequeue();
10-
if (i === n - 1 && j === m - 1) {
11-
return d;
12-
}
13-
if (d > dist[i][j]) {
14-
continue;
15-
}
16-
for (let k = 0; k < 4; ++k) {
17-
const [x, y] = [i + dirs[k], j + dirs[k + 1]];
12+
if (d > dist[i][j]) continue;
13+
if (i === n - 1 && j === m - 1) return d;
14+
for (let k = 0; k < 4; k++) {
15+
const x = i + dirs[k];
16+
const y = j + dirs[k + 1];
1817
if (x >= 0 && x < n && y >= 0 && y < m) {
19-
const t = Math.max(moveTime[x][y], dist[i][j]) + ((i + j) % 2) + 1;
20-
if (dist[x][y]>t) {
18+
const t = Math.max(moveTime[x][y], d) + ((i + j) % 2) + 1;
19+
if (t<dist[x][y]) {
2120
dist[x][y] = t;
2221
pq.enqueue([t, x, y]);
2322
}
2423
}
2524
}
2625
}
26+
return -1;
2727
}

0 commit comments

Comments
(0)

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