Leetcode 1095 Solution

This article provides solution to leetcode question 1095 (two-city-scheduling)

https://leetcode.com/problems/two-city-scheduling

Solution

class Solution:
    def twoCitySchedCost(self, costs: List[List[int]]) -> int:
        n = len(costs) // 2
        costs = sorted([(cost1 - cost2, cost1, cost2) for cost1, cost2 in costs])
        return sum([cost1 for _, cost1, _ in costs[0:n]] + [cost2 for _, _, cost2 in costs[n:]])