diff --git a/easy/count_prefix_and_suffix_pairs_i.py b/easy/count_prefix_and_suffix_pairs_i.py new file mode 100644 index 0000000..89c76a7 --- /dev/null +++ b/easy/count_prefix_and_suffix_pairs_i.py @@ -0,0 +1,17 @@ +# 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 +