LeetCode 3110. Score of a String in F#

URL

https://leetcode.com/problems/score-of-a-string/description/?envType=daily-question&envId=2024-06-01

Code

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

let scoreOfString (s: string) : int =
    let rec scoreOfString' cs prev acc =
        match cs with
        | [] -> acc
        | h :: t -> scoreOfString' t h (acc + abs (h - prev))

    let cs = s |> Seq.map int |> Seq.toList

    match cs with
    | [] -> failwith "never reach here"
    | h :: t -> scoreOfString' t h 0