Shohei Yoshida
Shohei Yoshida's Blog

Follow

Shohei Yoshida's Blog

Follow

452. Minimum Number of Arrows to Burst Balloons in F#

Shohei Yoshida's photo
Shohei Yoshida
·Jan 5, 2023·

1 min read

URL

Minimum Number of Arrows to Burst Balloons - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/0452/main.fsx

let findMinArrowShots (points: (int * int) list) : int =
    let rec findMinArrowShots' points (end1: int) acc =
        match points with
        | [] -> acc
        | (s, e) :: t ->
            if s <= end1 then
                findMinArrowShots' t (System.Math.Min(e, end1)) acc
            else
                findMinArrowShots' t e (acc + 1)

    let points = points |> List.sortWith (fun (s1, _) (s2, _) -> compare s1 s2)
    findMinArrowShots' (points.Tail) (snd points.Head) 1
 
Share this