3045. Count Prefix and Suffix Pairs II
You are given a 0-indexed string array
words
.Let’s define a boolean function
isPrefixAndSuffix
that takes two strings,str1
andstr2
:
isPrefixAndSuffix(str1, str2)
returnstrue
ifstr1
is both a prefix and a suffix ofstr2
, andfalse
otherwise.For example,
isPrefixAndSuffix("aba", "ababa")
istrue
because"aba"
is a prefix of"ababa"
and also a suffix, butisPrefixAndSuffix("abc", "abcd")
isfalse
.Return an integer denoting the number of index pairs
(i*,* j)
such thati < j
, andisPrefixAndSuffix(words[i], words[j])
istrue
.
c++
1 |
|