HTMLify
LeetCode - Count Prefix and Suffix Pairs I - Python
Views: 391 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 | class Solution: def isPrefixAndSuffix(self, str1: str, str2: str): return str2.startswith(str1) and str2.endswith(str1) def countPrefixSuffixPairs(self, words: List[str]) -> int: c = 0 for i in range(len(words)): for j in range(i+1, len(words)): if self.isPrefixAndSuffix(words[i], words[j]): c += 1 return c |