LeetCode 645. Set Mismatch in F#

URL

https://leetcode.com/problems/set-mismatch/description/

Code

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

let findErrorNums (nums: int list) : int * int =
    let len = List.length nums

    let rec findErrorNums' nums prev dup miss =
        match nums with
        | [] -> dup, (if miss = -1 then len else miss)
        | h :: t ->
            if h = prev then findErrorNums' t h h miss
            elif h = prev + 2 then findErrorNums' t h dup (h - 1)
            else findErrorNums' t h dup miss

    match List.sort nums with
    | [] -> failwith "never reach here"
    | h :: t -> findErrorNums' t h -1 (if h = 1 then -1 else 1)