1. 程式人生 > >500. Keyboard Row (5月26日)

500. Keyboard Row (5月26日)

() tor push_back str DC Go row ons OS

解答

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; } };

500. Keyboard Row (5月26日)