Created
October 26, 2018 15:38
-
-
Save zhangxiaomu01/7a1fe9ba79c4c818b9c91a2eee5143ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
private: | |
vector<string> dic_s = {"", "", "abc", "def", "ghi","jkl", "mno","pqrs", "tuv", "wxyz"}; | |
vector<string> result; | |
public: | |
void dfs(const string &digits, string s, int pos){ | |
int len = digits.size(); | |
if(pos >= len){ | |
return; | |
} | |
int subLen = dic_s[digits[pos] - '0'].size(); | |
for(int i = 0; i< subLen; i++) | |
{ | |
string dic_string = dic_s[digits[pos] - '0']; | |
string temp = s + dic_string[i]; | |
if(pos == len - 1) | |
{ | |
result.push_back(temp); | |
} | |
dfs(digits, temp, pos + 1); | |
} | |
} | |
vector<string> letterCombinations(string digits) { | |
dfs(digits, "", 0); | |
return result; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment