bumpsoo 2025-01-08 21:15:17 +09:00
parent 7fa53c90b0
commit 22857619c1

View file

@ -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