2025-08-22 15:53:34 +0000 UTC
Count Prefix and Suffix Pairs I
Categories:
Links
Code
class Solution:
def countPrefixSuffixPairs(self, words: List[str]) -> int:
res = 0
for i in range(len(words)):
w1 = words[i]
for j in range(i + 1, len(words)):
w2 = words[j]
if w2.startswith(w1) and w2.endswith(w1):
res += 1
return res