Skip to content

Commit b32ed04

Browse files
committed
Jan 8
1 parent bcf6a26 commit b32ed04

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from itertools import combinations
2+
from typing import List
3+
4+
5+
class Solution:
6+
def countPrefixSuffixPairs(self, words: List[str]) -> int:
7+
count = 0
8+
for str1, str2 in combinations(words, 2):
9+
count += str2.startswith(str1) and str2.endswith(str1)
10+
return count
11+
12+
13+
def main():
14+
words = ['a', 'aba', 'ababa', 'aa']
15+
assert Solution().countPrefixSuffixPairs(words) == 4
16+
17+
words = ['pa', 'papa', 'ma', 'mama']
18+
assert Solution().countPrefixSuffixPairs(words) == 2
19+
20+
words = ['abab', 'ab']
21+
assert Solution().countPrefixSuffixPairs(words) == 0
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-01-January-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
| January 5 | [2381. Shifting Letters II](https://leetcode.com/problems/shifting-letters-ii/) | Medium | Solved |
1111
| January 6 | [1769. Minimum Number of Operations to Move All Balls to Each Box](https://leetcode.com/problems/minimum-number-of-operations-to-move-all-balls-to-each-box/) | Medium | Solved |
1212
| January 7 | [1408. String Matching in an Array](https://leetcode.com/problems/string-matching-in-an-array/) | Easy | Solved |
13-
| January 8 | []() | | |
13+
| January 8 | [3042. Count Prefix and Suffix Pairs I](https://leetcode.com/problems/count-prefix-and-suffix-pairs-i/) | Easy | Solved |
1414
| January 9 | []() | | |
1515
| January 10 | []() | | |
1616
| January 11 | []() | | |
@@ -39,6 +39,6 @@
3939
## Summary
4040
| Level | Problems | Solved | Unsolved |
4141
| --- | --- | --- | --- |
42-
| Easy | 2 | 2 | 0 |
42+
| Easy | 3 | 3 | 0 |
4343
| Medium | 5 | 5 | 0 |
4444
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)