LeetCode 729. My Calendar I in F#
URL
Code
type MyCalendar =
{ Ranges: (int * int) list }
static member Empty: MyCalendar = { Ranges = [] }
static member Book (start: int) (end': int) (cal: MyCalendar) : (bool * MyCalendar) =
let ok = cal.Ranges |> List.forall (fun (s, e) -> start >= e || end' < s)
if ok then
true,
{ cal with
Ranges = (start, end') :: cal.Ranges }
else
false, cal