LeetCode 2270. Number of Ways to Split Array in F#

URL

https://leetcode.com/problems/number-of-ways-to-split-array/description/?envType=daily-question&envId=2025-01-03

Code

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

let waysToSplitArray (nums: int list) : int =
    let rec waysToSplitArray' (nums: int64 list) left right acc =
        match nums with
        | [] -> failwith "never reach here"
        | _ :: [] -> acc
        | h :: t ->
            let left = left + h
            let right = right - h
            waysToSplitArray' t left right (if left >= right then acc + 1 else acc)

    let nums = nums |> List.map int64
    let right = List.sum nums
    waysToSplitArray' nums 0L right 0