-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17.cpp
More file actions
37 lines (30 loc) · 973 Bytes
/
17.cpp
File metadata and controls
37 lines (30 loc) · 973 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
36
37
/*
* Written by Nitin Kumar Maharana
* nitin.maharana@gmail.com
*/
class Solution {
void letter(vector<string>& result, string& tempResult, string& digits, string *memory, int i, int n)
{
if(i == n)
{
result.push_back(tempResult);
return;
}
for(int j = 0; j < memory[digits[i]-'0'].size(); j++)
{
tempResult[i] = memory[digits[i]-'0'][j];
letter(result, tempResult, digits, memory, i+1, n);
}
return;
}
public:
vector<string> letterCombinations(string digits) {
string memory[10] = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
vector<string> result;
string tempResult(digits.size(), '0');
if(digits.size() == 0)
return result;
letter(result, tempResult, digits, memory, 0, digits.size());
return result;
}
};