Skip to content

Instantly share code, notes, and snippets.

@doyedele1
Created September 7, 2023 13:48
Show Gist options
  • Save doyedele1/11469cc97a43024bf01be0b88d28e642 to your computer and use it in GitHub Desktop.
Save doyedele1/11469cc97a43024bf01be0b88d28e642 to your computer and use it in GitHub Desktop.
Two City Scheduling
class Solution:
def twoCitySchedCost(self, costs: List[List[int]]) -> int:
costs = sorted(costs, key = lambda x: x[0] - x[1])
res = 0
n = len(costs) // 2
for i in range(n):
res += costs[i][0] + costs[i + n][1]
return res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment