1029. Two City Scheduling
https://leetcode.com/problems/two-city-scheduling/
Sort array by saving
Saving is defined as (a[0]-a[1]) for tuple a in the array
class Solution:
def twoCitySchedCost(self, costs: List[List[int]]) -> int:
res = 0
costs.sort(key=lambda x: x[0]-x[1])
n = len(costs)
for i in range(n):
if i < n//2:
res += costs[i][0]
else:
res+= costs[i][1]
return res
Last updated
Was this helpful?