LeetCode 881. Boats to Save People in F#

URL

https://leetcode.com/problems/boats-to-save-people/description/?envType=daily-question&envId=2024-05-04

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/challenge/202405/boats_to_save_people/main.fsx

let numRescueBoats (people: int list) (limit: int) : int =
    let rec numRescueBoats' (people: int[]) left right ret =
        if left > right then
            ret
        else
            let ret' = ret + 1

            if people.[left] + people.[right] <= limit then
                numRescueBoats' people (left + 1) (right - 1) ret'
            else
                numRescueBoats' people left (right - 1) ret'

    let people = people |> List.sort |> List.toArray
    numRescueBoats' people 0 (people.Length - 1) 0