2087. Minimum Cost Homecoming of a Robot in a Grid
Содержание
class Solution:
def minCost(
self,
startPos: List[int],
homePos: List[int],
rowCosts: List[int],
colCosts: List[int],
) -> int:
i, j = startPos
x, y = homePos
res = 0
if i < x:
res += sum(rowCosts[i + 1 : x + 1])
else:
res += sum(rowCosts[x:i])
if j < y:
res += sum(colCosts[j + 1 : y + 1])
else:
res += sum(colCosts[y:j])
return res