Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf08222

Browse files
committed
New Problem Solution - "1935. Maximum Number of Words You Can Type"
1 parent51ea33c commitcf08222

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ LeetCode
99

1010
| #| Title| Solution| Difficulty|
1111
|---| -----| --------| ----------|
12+
|1935|[Maximum Number of Words You Can Type](https://leetcode.com/problems/maximum-number-of-words-you-can-type/)|[C++](./algorithms/cpp/maximumNumberOfWordsYouCanType/MaximumNumberOfWordsYouCanType.cpp)|Easy|
1213
|1882|[Process Tasks Using Servers](https://leetcode.com/problems/process-tasks-using-servers/)|[C++](./algorithms/cpp/processTasksUsingServers/ProcessTasksUsingServers.cpp)|Medium|
1314
|1881|[Maximum Value after Insertion](https://leetcode.com/problems/maximum-value-after-insertion/)|[C++](./algorithms/cpp/maximumValueAfterInsertion/MaximumValueAfterInsertion.cpp)|Medium|
1415
|1880|[Check if Word Equals Summation of Two Words](https://leetcode.com/problems/check-if-word-equals-summation-of-two-words/)|[C++](./algorithms/cpp/checkIfWordEqualsSummationOfTwoWords/CheckIfWordEqualsSummationOfTwoWords.cpp)|Easy|
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Source : https://leetcode.com/problems/maximum-number-of-words-you-can-type/
2+
// Author : Hao Chen
3+
// Date : 2021-07-22
4+
5+
/*****************************************************************************************************
6+
*
7+
* There is a malfunctioning keyboard where some letter keys do not work. All other keys on the
8+
* keyboard work properly.
9+
*
10+
* Given a string text of words separated by a single space (no leading or trailing spaces) and a
11+
* string brokenLetters of all distinct letter keys that are broken, return the number of words in
12+
* text you can fully type using this keyboard.
13+
*
14+
* Example 1:
15+
*
16+
* Input: text = "hello world", brokenLetters = "ad"
17+
* Output: 1
18+
* Explanation: We cannot type "world" because the 'd' key is broken.
19+
*
20+
* Example 2:
21+
*
22+
* Input: text = "leet code", brokenLetters = "lt"
23+
* Output: 1
24+
* Explanation: We cannot type "leet" because the 'l' and 't' keys are broken.
25+
*
26+
* Example 3:
27+
*
28+
* Input: text = "leet code", brokenLetters = "e"
29+
* Output: 0
30+
* Explanation: We cannot type either word because the 'e' key is broken.
31+
*
32+
* Constraints:
33+
*
34+
* 1 <= text.length <= 10^4
35+
* 0 <= brokenLetters.length <= 26
36+
* text consists of words separated by a single space without any leading or trailing spaces.
37+
* Each word only consists of lowercase English letters.
38+
* brokenLetters consists of distinct lowercase English letters.
39+
******************************************************************************************************/
40+
41+
classSolution {
42+
public:
43+
intcanBeTypedWords(string text, string brokenLetters) {
44+
vector<bool>borken(26,false);
45+
46+
for (auto ch : brokenLetters) {
47+
borken[ch -'a'] =true;
48+
}
49+
50+
text +='';
51+
int cnt =0;
52+
for (int i =0; i < text.size(); i++ ) {
53+
if ( text[i] =='')continue;
54+
55+
bool skip =false;
56+
for (; text[i] !=''; i++ ) {
57+
if (borken[text[i] -'a'] ==true ) skip =true;
58+
}
59+
if ( !skip ) cnt++;
60+
}
61+
62+
return cnt;
63+
}
64+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp