-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKEYBOARD_ROW.cpp
More file actions
46 lines (40 loc) · 1.15 KB
/
KEYBOARD_ROW.cpp
File metadata and controls
46 lines (40 loc) · 1.15 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Solution {
public:
vector<string> keyboard;
map<char,int> lmap;
int rows;
Solution(){
keyboard.push_back("qwertyuiop");
keyboard.push_back("asdfghjkl");
keyboard.push_back("zxcvbnm");
rows = 3;
for(int i=0;i<3;i++){
int len = keyboard[i].length();
for(int j=0;j<len;j++){
lmap.insert(make_pair(keyboard[i][j],i));
}
}
}
vector<string> findWords(vector<string>& words) {
vector<string> res;
int sz = words.size();
for(int i=0;i<sz;i++)
{
int len = words[i].length();
string temp = words[i];
int cur_index = lmap[tolower(temp[0])];
int j=1;
for(;j<len;j++)
{
if(lmap[tolower(temp[j])]!=cur_index)
{
//cout<<"i. "<<temp<<" expected"<<cur_index<<" but "<<lmap[tolower(temp[j])]<<endl;
break;
}
}
if(j>=len)
res.push_back(temp);
}
return res;
}
};