Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ class Solution {
public:
int canBeTypedWords(string text, string brokenLetters) {
bool s[26]{};
for (char& c : brokenLetters) {
for (char c : brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
for (auto& w : split(text, ' ')) {
for (char& c : w) {
stringstream ss(text);
string w;
while (ss >> w) {
for (char c : w) {
if (s[c - 'a']) {
--ans;
break;
Expand All @@ -131,21 +133,6 @@ public:
}
return ans;
}

vector<string> split(const string& s, char c) {
vector<string> ans;
string t;
for (char d : s) {
if (d == c) {
ans.push_back(t);
t.clear();
} else {
t.push_back(d);
}
}
ans.push_back(t);
return ans;
}
};
```

Expand Down Expand Up @@ -217,6 +204,31 @@ impl Solution {
}
```

#### C#

```cs
public class Solution {
public int CanBeTypedWords(string text, string brokenLetters) {
bool[] s = new bool[26];
foreach (char c in brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
string[] words = text.Split(' ');
foreach (string w in words) {
foreach (char c in w) {
if (s[c - 'a']) {
--ans;
break;
}
}
++ans;
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ class Solution {
public:
int canBeTypedWords(string text, string brokenLetters) {
bool s[26]{};
for (char& c : brokenLetters) {
for (char c : brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
for (auto& w : split(text, ' ')) {
for (char& c : w) {
stringstream ss(text);
string w;
while (ss >> w) {
for (char c : w) {
if (s[c - 'a']) {
--ans;
break;
Expand All @@ -132,21 +134,6 @@ public:
}
return ans;
}

vector<string> split(const string& s, char c) {
vector<string> ans;
string t;
for (char d : s) {
if (d == c) {
ans.push_back(t);
t.clear();
} else {
t.push_back(d);
}
}
ans.push_back(t);
return ans;
}
};
```

Expand Down Expand Up @@ -218,6 +205,31 @@ impl Solution {
}
```

#### C#

```cs
public class Solution {
public int CanBeTypedWords(string text, string brokenLetters) {
bool[] s = new bool[26];
foreach (char c in brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
string[] words = text.Split(' ');
foreach (string w in words) {
foreach (char c in w) {
if (s[c - 'a']) {
--ans;
break;
}
}
++ans;
}
return ans;
}
}
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ class Solution {
public:
int canBeTypedWords(string text, string brokenLetters) {
bool s[26]{};
for (char& c : brokenLetters) {
for (char c : brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
for (auto& w : split(text, ' ')) {
for (char& c : w) {
stringstream ss(text);
string w;
while (ss >> w) {
for (char c : w) {
if (s[c - 'a']) {
--ans;
break;
Expand All @@ -17,19 +19,4 @@ class Solution {
}
return ans;
}

vector<string> split(const string& s, char c) {
vector<string> ans;
string t;
for (char d : s) {
if (d == c) {
ans.push_back(t);
t.clear();
} else {
t.push_back(d);
}
}
ans.push_back(t);
return ans;
}
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public class Solution {
public int CanBeTypedWords(string text, string brokenLetters) {
bool[] s = new bool[26];
foreach (char c in brokenLetters) {
s[c - 'a'] = true;
}
int ans = 0;
string[] words = text.Split(' ');
foreach (string w in words) {
foreach (char c in w) {
if (s[c - 'a']) {
--ans;
break;
}
}
++ans;
}
return ans;
}
}