forked from Nimesh-Srivastava/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0017.cpp
More file actions
30 lines (22 loc) · 668 Bytes
/
Copy path0017.cpp
File metadata and controls
30 lines (22 loc) · 668 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
class Solution {
public:
vector<string> mappings = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"}, ans;
void backtrack(string& digits, int pos, string& temp){
if(pos == digits.size()) {
ans.push_back(temp);
return;
}
for(auto c : mappings[digits[pos] - '2']){
temp.push_back(c);
backtrack(digits, pos + 1, temp);
temp.pop_back();
}
}
vector<string> letterCombinations(string digits) {
if(digits == "")
return ans;
string temp = "";
backtrack(digits, 0, temp);
return ans;
}
};