题目
解法
解法1:最短路径问题(TLE)
bellman ford
class Solution:
def minCost(self, startPos: List[int], homePos: List[int], rowCosts: List[int], colCosts: List[int]) -> int:
m,n = len(rowCosts),len(colCosts)
dists = [[float('inf')] * n for _ in range(m)]
dists[startPos[0]][startPos[1]] = 0
dirs = [[0,1],[0,-1],[1,0],[-1,0]]
q = collections.deque()
q.append(startPos)
while q:
i,j = q.popleft()
for d in dirs:
x,y = i + d[0],j + d[1]
if x < 0 or x >= m or y < 0 or y >= n: