-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.cpp
More file actions
25 lines (25 loc) · 716 Bytes
/
17.cpp
File metadata and controls
25 lines (25 loc) · 716 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
class Solution {
public:
vector<string> letterCombinations(string digits) {
string phone[10] = {"0", "1","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int n = digits.size();
if(n==0)
return {};
vector<string> res;
vector<int> number(n);
for(int i=0;i<n;i++)
number[i] = digits[i]-'0';
queue<string> q;
q.push("");
while(!q.empty()){
string curr = q.front();q.pop();
if(curr.size() == n)
res.push_back(curr);
else{
for(auto v: phone[number[curr.size()]])
q.push(curr+v);
}
}
return res;
}
};