500.鍵盤行
阿新 • • 發佈:2018-12-03
class Solution { public: vector<string> findWords(vector<string>& words) { vector<string>ans; string line1 = "qwertyuiop"; string line2 = "asdfghjkl"; string line3 = "zxcvbnm"; for (int i = 0; i < words.size(); i++) { int j = 0; while (line1.find(tolower(words[i][j])) != string::npos) { j++; if (j == words[i].length()) ans.push_back(words[i]); } j = 0; while (line2.find(tolower(words[i][j])) != string::npos) { j++; if (j == words[i].length()) ans.push_back(words[i]); } j = 0; while (line3.find(tolower(words[i][j])) != string::npos) { j++; if (j == words[i].length() ) ans.push_back(words[i]); } } return ans; } };