题目描述:
1935. 可以输入的最大单词数 - 力扣(LeetCode) (leetcode-cn.com)
自测用例:
"hello world"
"ad"
"leet code"
"lt"
"leet code"
"e"
Java代码:
class Solution {
public int canBeTypedWords(String text, String brokenLetters) {
String[] words=text.split(" ");
int ans=words.length;
for(String word:words){
for(int i=brokenLetters.length()-1;i>=0;i--){
if(word.indexOf(brokenLetters.charAt(i))!=-1){
ans--;
break;
}
}
}
return ans;
}
}
class Solution {
public int canBeTypedWords(String t, String b) {
boolean[] set=new boolean['z'+1];
for(char c:b.toCharArray())set[c]=true;
String[] ws=t.split(" ");
int ans=ws.length;
for(String w:ws){
for(char c:w.toCharArray()){
if(set[c]){
ans--;
break;
}
}
}
return ans;
}
}
?
|