Skip to content

Commit bf5c993

Browse files
committed
Runtime: 252 ms (Top 66.67%) | Memory: 50.7 MB (Top 73.33%)
1 parent 264d462 commit bf5c993

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/M/Minimum Moves to Move a Box to Their Target Location/Minimum Moves to Move a Box to Their Target Location.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// Runtime: 252 ms (Top 66.67%) | Memory: 50.7 MB (Top 73.33%)
12
/**
23
* @param {character[][]} grid
34
* @return {number}
45
*/
56
var minPushBox = function(grid) {
6-
// common info & utils
7+
// common info & utils
78
const m = grid.length
89
const n = grid[0].length
910
const dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]
@@ -12,7 +13,7 @@ var minPushBox = function(grid) {
1213
const validate = ([x, y]) => x >= 0 && y >= 0 && x < m && y < n
1314
const getKey = ([x, y]) => x * n + y
1415

15-
// find all player, ball, target, and free cells
16+
// find all player, ball, target, and free cells
1617
const init = () => {
1718
let player
1819
let ball
@@ -39,7 +40,7 @@ var minPushBox = function(grid) {
3940
const { player, ball, target, freeSet } = init()
4041
const targetKey = getKey(target)
4142

42-
// detect whether two cells are connected
43+
// detect whether two cells are connected
4344
const connCache = new Map() // [x,y,x2,y2,x3,y3] => boolean
4445
const getConnKey = (a, b, ball) => {
4546
if (
@@ -88,7 +89,7 @@ var minPushBox = function(grid) {
8889
return false
8990
}
9091

91-
// solve the game
92+
// solve the game
9293
const getStateKey = ([x, y], [xx, yy]) => [x, y, xx, yy].join(',') // ball, player
9394
const stateCache = new Set() // Set<stateKey>
9495
let queue = [[ball, player]]
@@ -127,4 +128,4 @@ var minPushBox = function(grid) {
127128
count++
128129
}
129130
return -1
130-
};
131+
};

0 commit comments

Comments
 (0)