LeetCode 1239. Maximum Length of a Concatenated String with Unique Characters in F#

URL

leetcode.com/problems/maximum-length-of-a-c..

Code

github.com/syohex/dotnet-study/blob/master/..

let maxLength (arr: string list) : int =
    let rec maxLength' (arr: string list) (cands: string list) ret =
        match arr with
        | [] -> ret
        | h :: t ->
            let cands' =
                cands
                |> List.fold
                    (fun acc cand ->
                        let tmp = cand + h
                        let chars = tmp |> Set.ofSeq |> Seq.length

                        if chars = tmp.Length then
                            tmp :: acc
                        else
                            acc)
                    cands

            let ret' =
                cands'
                |> List.fold (fun acc s -> System.Math.Max(acc, s.Length)) 0

            maxLength' t cands' ret'

    maxLength' arr [ "" ] 0