LeetCode 2000. Reverse Prefix of Word in F#

URL

Reverse Prefix of Word - LeetCode

Code

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

open System

let reversePrefix (word: string) (ch: char) : string =
    let rec reversePrefix' (cs: char list) ch acc =
        match cs with
        | [] -> word
        | h :: t ->
            if h = ch then
                (h :: acc) @ t |> String.Concat
            else
                reversePrefix' t ch (h :: acc)

    reversePrefix' (Seq.toList word) ch []