Skip to content

Commit 502eac0

Browse files
committed
simple, backtracking - Yelp
1 parent 655e796 commit 502eac0

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Solution/Day-081.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution {
2+
vector<string> dialer = {
3+
"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"
4+
};
5+
vector<string>result;
6+
void getString(string &digits, int index, string currentString) {
7+
if (index >= digits.size()) {
8+
result.push_back(currentString);
9+
return;
10+
}
11+
for (auto & itr: dialer[digits[index]-'0']) {
12+
getString(digits, index+1, currentString+itr);
13+
}
14+
return ;
15+
}
16+
public:
17+
vector<string> letterCombinations(string digits) {
18+
result.clear();
19+
if (digits.size() != 0) {
20+
getString(digits, 0, "");
21+
}
22+
return result;
23+
}
24+
};
25+

0 commit comments

Comments
 (0)