HTMLify

LeetCode - Count Prefix and Suffix Pairs I - Python
Views: 20 | Author: abh
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

Comments