Skip to content

Commit d356fba

Browse files
committed
D. J.:
- Added the leetcode problem and solution for 1935
1 parent fdb7648 commit d356fba

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@
292292
- [1912 Design Movie Rental System](https://leetcode.com/problems/design-movie-rental-system/description/)
293293
- [1991 Find the Middle Index in Array](https://leetcode.com/problems/find-the-middle-index-in-array/description/)
294294
- [1922 Count Good Numbers](https://leetcode.com/problems/count-good-numbers/description/)
295+
- [1935 Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type/description/)
295296
- [1964 Find the Longest Valid Obstacle Course at Each Position](https://leetcode.com/problems/find-the-longest-valid-obstacle-course-at-each-position/description/)
296297
- [2140 Solving Questions With Brainpower](https://leetcode.com/problems/solving-questions-with-brainpower/description/)
297298
- [2215 Find the Difference of Two Arrays](https://leetcode.com/problems/find-the-difference-of-two-arrays/description/)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
"""Base class for all LeetCode Problems."""
3+
4+
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
5+
"""
6+
There is a malfunctioning keyboard where some letter keys do not work. All other
7+
keys on the keyboard work properly.
8+
9+
Given a string text of words separated by a single space (no leading or trailing
10+
spaces) and a string brokenLetters of all distinct letter keys that are broken,
11+
return the number of words in text you can fully type using this keyboard.
12+
13+
"""
14+
words = text.split(" ")
15+
broken = set(brokenLetters)
16+
res = len(words)
17+
for word in words:
18+
for c in word:
19+
if c in broken:
20+
res -= 1
21+
break
22+
return res
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from awesome_python_leetcode._1935_maximum_number_of_words_you_can_type import Solution
4+
5+
6+
@pytest.mark.parametrize(
7+
argnames=["text", "brokenLetters", "expected"],
8+
argvalues=[
9+
("hello world", "ad", 1),
10+
("leet code", "lt", 1),
11+
("leet code", "e", 0),
12+
],
13+
)
14+
def test_func(text: str, brokenLetters: str, expected: int):
15+
"""Tests the solution of a LeetCode problem."""
16+
num_typed_words = Solution().canBeTypedWords(text, brokenLetters)
17+
assert num_typed_words == expected

0 commit comments

Comments
 (0)