2
def minPushBox(self, grid: List[List[str]]) -> int:3
m, n = len(grid), len(grid[0])5
start, target, box = (0, 0), (0, 0), (0, 0)10
elif grid[i][j] == "T":12
elif grid[i][j] == "S":14
q.append((box[0], box[1], 0, start[0], start[1]))16
directions = ((1, 0, -1, 0), (0, 1, 0, -1), (-1, 0, 1, 0), (0, -1, 0, 1))17
visited.add(box + box)19
def solve(i, j, bi, bj):21
if (i, j) == (bi, bj):25
ni, nj = i + d[0], j + d[1]29
and (ni, nj) not in seen30
and grid[ni][nj] != "#"33
ans = ans or solve(ni, nj, bi, bj)39
i, j, pushes, si, sj = q.popleft()45
ni, nj, bi, bj = i + d[0], j + d[1], i + d[2], j + d[3]49
and (ni, nj, i, j) not in visited50
and grid[ni][nj] != "#"53
and grid[bi][bj] != "#"58
res = solve(si, sj, bi, bj)62
visited.add((ni, nj, i, j))63
q.append((ni, nj, pushes + 1, i, j))