-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.cpp
More file actions
35 lines (31 loc) · 886 Bytes
/
17.cpp
File metadata and controls
35 lines (31 loc) · 886 Bytes
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
class Solution {
public:
vector<vector<char>> tele = {
{'a', 'b', 'c'},
{'d', 'e', 'f'},
{'g', 'h', 'i'},
{'j', 'k', 'l'},
{'m', 'n', 'o'},
{'p', 'q', 'r', 's'},
{'t', 'u', 'v'},
{'w', 'x', 'y', 'z'}
};
vector<string> letterCombinations(string digits) {
vector<string> ans;
if(digits.length() == 0) return ans;
queue<string> q; q.push("");
for(char d : digits){
int cur = q.front().length();
while(q.front().length() == cur){
string s = q.front(); q.pop();
for(char c : tele[d-'2']){
q.push(s + c);
}
}
}
while(!q.empty()){
ans.push_back(q.front()); q.pop();
}
return ans;
}
};