Skip to content

Commit 4e63144

Browse files
authored
Create maximum-number-of-words-you-can-type.cpp
1 parent 3c0c967 commit 4e63144

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int canBeTypedWords(string text, string brokenLetters) {
7+
unordered_set<char> lookup(cbegin(brokenLetters), cend(brokenLetters));
8+
int result = 0;
9+
bool broken = false;
10+
for (const auto& c : text) {
11+
if (c == ' ') {
12+
result += int(broken == false);
13+
broken = false;
14+
} else if (lookup.count(c)) {
15+
broken = true;
16+
}
17+
}
18+
return result + int(broken == false);
19+
}
20+
};

0 commit comments

Comments
 (0)