Created
September 7, 2023 13:48
-
-
Save doyedele1/11469cc97a43024bf01be0b88d28e642 to your computer and use it in GitHub Desktop.
Two City Scheduling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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