LeetCode 2161. Partition Array According to Given Pivot in F#

URL

Partition Array According to Given Pivot - LeetCode

Code

https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/challenge/202503/partition_array_according_to_given_pivot/main.fsx

let pivotArray (nums: int list) (pivot: int) : int list =
    nums
    |> List.fold
        (fun (acc1, acc2, acc3) n ->
            if n < pivot then n :: acc1, acc2, acc3
            elif n = pivot then acc1, n :: acc2, acc3
            else acc1, acc2, n :: acc3)
        ([], [], [])
    |> fun (acc1, acc2, acc3) -> acc3 @ acc2 @ acc1
    |> List.rev