Letter Combinations of a Phone Number(C++)
given a string containing digits from2-9inclusive, return all possible letter combinations that the number could represent.
a mapping of digit to letters (just like on the telephone buttons) is given below. note that 1 does not map to any letters.
class solution {
public:
vector
{
int n=digits.size();
vector
if(n==0)
return ret;
string dict[]={"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
findall(digits,dict,0,"",ret);
return ret;
}
void findall(string digits,string dict[],int level,string out,vector
{
if(level==digits.size())
return ret.push_back(out);
else
{
string str=dict[digits[level]-'2'];
for(int i=0;i
{
out.push_back(str[i]);
findall(digits,dict,level+1,out,ret);
out.pop_back();
}
}
}
};
推荐阅读
-
Leetcode 17. Letter Combinations of a Phone Number(python)
-
LeetCode 17. Letter Combinations of a Phone Number
-
Letter Combinations of a Phone Number(C++)
-
leetcode17:Letter Combinations of a Phone Number
-
LeetCode 17. 电话号码的字母组合 Letter Combinations of a Phone Number
-
leetcode--17. Letter Combinations of a Phone Number
-
LeetCode 17. Letter Combinations of a Phone Number
-
17. Letter Combinations of a Phone Number (Python) dfs(递归 recursion) + 迭代(iterative)
-
Letter Combinations of a Phone Number(C++)