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
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