LeetCode 645. Set Mismatch in F#
URL
leetcode.com/problems/set-mismatch
Code
github.com/syohex/dotnet-study/blob/master/..
let findErrorNums (nums: int list) : (int * int) =
let rec findErrorNums' nums duplicated acc =
match nums with
| [] -> duplicated, (Array.findIndex (fun n -> n = 0) acc) + 1
| h :: t ->
acc.[h - 1] <- acc.[h - 1] + 1
if acc.[h - 1] = 2 then
findErrorNums' t h acc
else
findErrorNums' t duplicated acc
findErrorNums' nums -1 (Array.zeroCreate nums.Length)