-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path792.py
More file actions
28 lines (28 loc) · 883 Bytes
/
Copy path792.py
File metadata and controls
28 lines (28 loc) · 883 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
class Solution:
def numMatchingSubseq(self, S: 'str', words: 'List[str]') -> 'int':
str = {}
for s in range(len(S)):
if S[s] not in str:
str[S[s]] = []
str[S[s]].append(s)
total = 0
for word in words:
sub, exist = -1, True
for w in word:
if w not in str:
exist = False
break
x, y, mid = 0, len(str[w]), 0
while x < y:
mid = x + (y - x) // 2
if str[w][mid] > sub:
y = mid
else:
x = mid + 1
if x == len(str[w]):
exist = False
break
sub = str[w][y]
if exist:
total += 1
return total