-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
35 lines (32 loc) · 904 Bytes
/
solution.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
26
27
28
29
30
31
32
33
34
35
class Solution
{
public:
vector<string> letterCombinations(string digits)
{
vector<string> result;
if(digits == "")
return result;
result.push_back("");
vector<string> dict(10);
dict[2] = "abc";
dict[3] = "def";
dict[4] = "ghi";
dict[5] = "jkl";
dict[6] = "mno";
dict[7] = "pqrs";
dict[8] = "tuv";
dict[9] = "wxyz";
for(int i = 0; i < digits.size(); i ++)
{
int size = result.size();
for(int j = 0; j < size; j ++)
{
string current = result[0];
result.erase(result.begin());
for(int k = 0; k < dict[digits[i]-'0'].size(); k ++)
result.push_back(current + dict[digits[i]-'0'][k]);
}
}
return result;
}
};