# https://leetcode.com/problems/count-prefix-and-suffix-pairs-i from typing import List class Solution: def countPrefixSuffixPairs(self, words: List[str]) -> int: result = 0 for i in range(len(words)): for j in range(i + 1, len(words)): if len(words[i]) > len(words[j]): continue result += int( words[i] == words[j][0:len(words[i])] and words[i] == words[j][-len(words[i]):] ) return result