1
const moves = [
2
[1, 0],
3
[0, 1],
4
[-1, 0],
5
[0, -1],
6
];
7

8
var swimInWater = function (grid) {
9
let pq = new MinPriorityQueue(),
10
N = grid.length - 1,
11
ans = grid[0][0],
12
i = 0,
13
j = 0;
14
while (i < N || j < N) {
15
for (let [a, b] of moves) {
16
let ia = i + a,
17
jb = j + b;
18
if (ia < 0 || ia > N || jb < 0 || jb > N || grid[ia][jb] > 2500) continue;
19
pq.enqueue((grid[ia][jb] << 12) + (ia << 6) + jb);
20
grid[ia][jb] = 3000;
21
}
22
let next = pq.dequeue().element;
23
ans = Math.max(ans, next >> 12);
24
i = (next >> 6) & ((1 << 6) - 1);
25
j = next & ((1 << 6) - 1);
26
}
27
return ans;
28
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0