Skip to content

Commit 33d089a

Browse files
committed
Runtime: 851 ms (Top 55.45%) | Memory: 16.4 MB (Top 32.26%)
1 parent a0dcdf4 commit 33d089a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1+
# Runtime: 851 ms (Top 55.45%) | Memory: 16.4 MB (Top 32.26%)
12
class Solution:
23
def numMatchingSubseq(self, s: str, words: List[str]) -> int:
34
word_dict = defaultdict(list)
45
numMatch = 0
56
# add words into bucket with key as order of the first letter
67
for w in words:
78
word_dict[ord(w[0])-ord('a')].append(w)
8-
# loop through the characters in s
9+
# loop through the characters in s
910
for c in s:
1011
qualified = word_dict[ord(c)-ord('a')]
1112
word_dict[ord(c)-ord('a')] = []
1213
for q in qualified:
13-
# if the word starts with the specified letter. i.e this is the last letter of the word
14+
# if the word starts with the specified letter. i.e this is the last letter of the word
1415
if len(q) == 1:
1516
numMatch += 1
1617
else:
1718
word_dict[ord(q[1])-ord('a')].append(q[1:])
1819
return numMatch
19-

0 commit comments

Comments
 (0)