LeetCode 1029. Two City Scheduling in F#
URL
leetcode.com/problems/two-city-scheduling
Code
github.com/syohex/dotnet-study/blob/master/..
let twoCitySchedCost (costs: (int * int) list) : int =
let costs' =
costs
|> List.sortWith (fun (a0, a1) (b0, b1) -> compare (a0 - a1) (b0 - b1))
let half = costs.Length / 2
let costA =
costs'
|> List.take half
|> List.map fst
|> List.sum
let costB =
costs'
|> List.skip half
|> List.map snd
|> List.sum
costA + costB