Skip to content

Commit 88441b3

Browse files
authored
Create maximum-number-of-words-you-can-type.py
1 parent 4e63144 commit 88441b3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def canBeTypedWords(self, text, brokenLetters):
6+
"""
7+
:type text: str
8+
:type brokenLetters: str
9+
:rtype: int
10+
"""
11+
lookup = set(brokenLetters)
12+
result, broken = 0, False
13+
for c in text:
14+
if c == ' ':
15+
result += int(broken == False)
16+
broken = False
17+
elif c in lookup:
18+
broken = True
19+
return result + int(broken == False)

0 commit comments

Comments
 (0)