-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path500.cpp
25 lines (25 loc) · 944 Bytes
/
500.cpp
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
class Solution {
public:
vector<string> findWords(vector<string> &words) {
string tempRow0 = "qwertyuiop", tempRow1 = "asdfghjkl", tempRow2 = "zxcvbnm";
unordered_set<char> first(tempRow0.begin(), tempRow0.end()),
second(tempRow1.begin(), tempRow1.end()),
third(tempRow2.begin(), tempRow2.end());
vector<string> ret;
for (auto word : words) {
bool row = true;
unordered_set<char> temp;
temp = (first.find(tolower(word[0])) == first.end() ?
(second.find(tolower(word[0])) == second.end() ? third : second) : first);
for (int i = 1; i < word.size(); ++i) {
if (temp.find(tolower(word[i])) == temp.end()) {
row = false;
break;
}
}
if (row)
ret.push_back(word);
}
return ret;
}
};