class Solution {
public:
unordered_set<char> set1 = {'q', 'w', 'e', 'r', 't', 'y','u', 'i', 'o', 'p'};
unordered_set<char> set2 = {'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'};
unordered_set<char> set3 = {'z', 'x', 'c', 'v', 'b', 'n', 'm'};
vector<string> findWords(vector<string>& words) {
vector<string> res;
for (auto& str: words) {
bool flag = false;
if (set1.count(tolower(str[0]))) {
flag = check(str, set1);
} else if (set2.count(tolower(str[0]))) {
flag = check(str, set2);
} else if (set3.count(tolower(str[0]))) {
flag = check(str, set3);
}
if (flag) {
res.push_back(str);
}
}
return res;
}
bool check(string str, unordered_set<char> set){
transform(str.begin(),str.end(),str.begin(),::tolower);
for (int i = 1; i < str.length(); i++) {
if (!set.count(str[i])) {
return false;
}
}
return true;
}
};