LeetCode 71. Simplify Path in F#

URL

leetcode.com/problems/simplify-path

Code

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

open System

let simplyfyPath (path: string) : string =
    let rec simplyfyPath' parts (acc: string list) =
        match parts with
        | [] -> sprintf "/%s" (String.Join("/", (acc |> List.rev)))
        | head :: tail ->
            match head with
            | "."
            | "" -> simplyfyPath' tail acc
            | ".." ->
                match acc with
                | [] -> simplyfyPath' tail acc
                | _ :: tail2 -> simplyfyPath' tail tail2
            | _ -> simplyfyPath' tail (head :: acc)

    let parts = path.Split '/' |> Array.toList
    simplyfyPath' parts []