3042. Count Prefix and Suffix Pairs I
🟩 Easy
Solution
My Solution
func countPrefixSuffixPairs(words []string) int {
count := 0
for i, word := range words {
for j:=i+1; j<len(words); j++ {
if len(word) <= len(words[j]) && isPrefixAndSuffix(words[j], word) {
count++
}
}
}
return count
}
func isPrefixAndSuffix(word1, word2 string) bool {
return strings.HasPrefix(word1, word2) && strings.HasSuffix(word1, word2)
}

Leetcode: link
Previous2657. Find the Prefix Common Array of Two ArraysNext3105. Longest Strictly Increasing or Strictly Decreasing Subarray
Last updated
Was this helpful?