LeetCode 1957. Delete Characters to Make Fancy String in F#

URL

Delete Characters to Make Fancy String - LeetCode

Code

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

open System

let makeFancyString (s: string) : string =
    let rec makeFancyString' cs prev1 prev2 (acc: char list) =
        match cs with
        | [] -> List.rev acc |> String.Concat
        | h :: t ->
            if h = prev1 && h = prev2 then
                makeFancyString' t h prev1 acc
            else
                makeFancyString' t h prev1 (h :: acc)

    makeFancyString' (Seq.toList s) '?' '?' []