1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
class Solution { public: bool check(const string& word, const string& row) { for(char c : word) { if(row.find(tolower(c)) == string::npos) return false; } return true; } vector<string> findWords(vector<string>& words) { const vector<string> rows = { "qwertyuiop", "asdfghjkl", "zxcvbnm" }; vector<string> ans; for(const auto& word : words) { for(const auto& row : rows) { if(check(word, row)) { ans.push_back(word); break; } } } return ans; } }; |