LeetCode 1636. Sort Array by Increasing Frequency in F#

URL

Sort Array by Increasing Frequency - LeetCode

Code

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

let frequencySort (nums: int list) : int list =
    let freq = nums |> List.countBy id |> Map.ofList

    nums
    |> List.sortWith (fun a b ->
        match Map.find a freq, Map.find b freq with
        | x, y when x = y -> compare b a
        | x, y -> compare x y)