LeetCode 3042. Count Prefix and Suffix Pairs I in F#
URL
Count Prefix and Suffix Pairs I - LeetCode
Code
let countPrefixSuffixPairs (words: string list) : int =
let isPrefixAndSuffix (str1: string) (str2: string) : bool =
str2.StartsWith(str1) && str2.EndsWith(str1)
let rec countPrefixSuffixPairs' words acc =
match words with
| [] -> acc
| h :: t ->
let n = List.filter (fun s -> isPrefixAndSuffix h s) t |> List.length
countPrefixSuffixPairs' t (acc + n)