解答
class Solution {
public:
vector<string> findWords(vector<string>& words) {
vector<string> result;
string first{"qwertyuiopQWERTYUIOP"};
string second{"asdfghjklASDFGHJKL"};
string third{"zxcvbnmZXCVBNM"};
for(auto it=words.begin();it!=words.end();++it){
bool flag1=findchar(first,*it);
bool flag2=findchar(second,*it);
bool flag3=findchar(third,*it);
if(flag1==true||flag2==true||flag3==true){
result.push_back(*it);
}
}
return result;
}
bool findchar(const string & str,const string & goal){
for(auto ch:goal){
if(str.find(ch)==string::npos){
return false;
}
}
return true;
}
};
原文地址:https://www.cnblogs.com/cs-niaocai/p/9094030.html
时间: 2024-10-09 02:13:31