1029. Two City Scheduling
一点都不easy啊...竟然是这样greedy
出来的,让我想起比较优势理论 Comparative advantage。
12/27/2020 Update:
也可以用DP做,但这题没法记忆,会TLE。Try to assign a person to both cities if its possible (a typical DP technique) and return the minimum of it.
class Solution:
def twoCitySchedCost(self, costs: List[List[int]]) -> int:
res = 0
costs.sort(key=lambda x: x[0]-x[1])
for i in range(len(costs)//2):
res += costs[i][0] + costs[-i-1][1]
return res
Last updated
Was this helpful?