Given an m x n integer grid grid, where each cell contains one of three values:
You want to place a house on an empty land cell (
Return the minimum total travel distance for such a placement. If no valid empty land cell can reach all buildings, return
Note: The total travel distance is the sum of the shortest path distances from the chosen empty land cell to every building in the grid.
Constraints:
m == grid.length
n == grid[i].length
m, n
grid[i][j] is either
There will be at least grid
Given an m x n integer grid grid, where each cell contains one of three values:
You want to place a house on an empty land cell (
Return the minimum total travel distance for such a placement. If no valid empty land cell can reach all buildings, return
Note: The total travel distance is the sum of the shortest path distances from the chosen empty land cell to every building in the grid.
Constraints:
m == grid.length
n == grid[i].length
m, n
grid[i][j] is either
There will be at least grid