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();
}
}
}
};
如对本文有疑问, 点击进行留言回复!!
【专题2:qt工程师】 之 【47.基于ffmpeg的播放器源码和可执行文件】
vs2017配置#include 「pylon/PylonIncludes.h」
#define swap(a,b) a^=b^=a^=b的问题 | 交换宏的错误
网友评论