-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumOfStrings.py
More file actions
29 lines (25 loc) · 975 Bytes
/
numOfStrings.py
File metadata and controls
29 lines (25 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring
in word.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input: patterns = ["a","abc","bc","d"], word = "abc"
Output: 3
Explanation:
- "a" appears as a substring in "abc".
- "abc" appears as a substring in "abc".
- "bc" appears as a substring in "abc".
- "d" does not appear as a substring in "abc".
3 of the strings in patterns appear as a substring in word.
Runtime: 52 ms, faster than 49.80% of Python3 online submissions for Number of Strings That Appear as Substrings in
Word.
Memory Usage: 13.9 MB, less than 84.67% of Python3 online submissions for Number of Strings That Appear as Substrings
in Word.
"""
class Solution:
def numOfStrings(self, patterns: list[str], word: str) -> int:
count = 0
for i in patterns:
if i in word:
count += 1
return count