LeetCode 131. Palindrome Partitioning in F#

URL

https://leetcode.com/problems/palindrome-partitioning/description/

Code

https://github.com/syohex/dotnet-study/blob/master/fsharp/leetcode/problems/0131/main.fsx

let partition (s: string) : string list list =
    let isPalindrome (s: char list) : bool = s = List.rev s

    let rec partition' (cs: char list) (acc: char list list) (ret: string list list) =
        match cs with
        | [] ->
            let strs =
                acc
                |> List.rev
                |> List.map (fun c -> System.String.Concat(Array.ofList c))

            strs :: ret
        | _ ->
            seq { 1 .. cs.Length }
            |> Seq.map (fun n -> List.take n cs, List.skip n cs)
            |> Seq.filter (fun (head, _) -> isPalindrome head)
            |> Seq.fold (fun ret' (head, rest) -> partition' rest (head :: acc) ret') ret

    partition' (s |> Seq.toList) [] []