This commit is contained in:
parent
7fa53c90b0
commit
22857619c1
1 changed files with 17 additions and 0 deletions
17
easy/count_prefix_and_suffix_pairs_i.py
Normal file
17
easy/count_prefix_and_suffix_pairs_i.py
Normal 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
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue