LeetCode 1759. Count Number of Homogenous Substrings in F#
URL
Count Number of Homogenous Substrings - LeetCode
Code
https://github.com/syohex/dotnet-study/tree/master/fsharp/leetcode/problems/1759/main.fsx
let countHomogenous (s: string) : int =
let modulo = 1_000_000_007
let rec countHomonogenous' cs prev count acc =
match cs with
| [] -> acc
| h :: t ->
if h = prev then
let count' = count + 1
countHomonogenous' t h count' ((acc + count') % modulo)
else
countHomonogenous' t h 1 ((acc + 1) % modulo)
let cs = Seq.toList s
countHomonogenous' (List.tail cs) (List.head cs) 1 1