? ?電話號碼的字母組合
class Solution {
string _num[10] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
public:
void Combinations(const string& digits,int di,string numcom,vector<string>& v)
{
if(di == digits.size())//結(jié)束條件
{
v.push_back(numcom);
return ;
}
int num = digits[di] - '0';
string str = _num[num];
for(auto ch : str)
{
Combinations(digits,di+1,numcom+ch,v);//遞歸一定要注意numcom是+
//不是+=;
}
}
vector<string> letterCombinations(string digits) {
vector<string> v;
if(digits.size() == 0)
{
return {};
}
int di = 0;
Combinations(digits,di,"",v);
return v;
}
};
楊輝三角?
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> vv;
vv.resize(numRows,vector<int>());//進行初始化
//進行的是每行初始化,因為這里表示的是順序表里面是個順序表
for(int i = 0; i < vv.size(); i++)//初始化沒列
{
vv[i].resize(i+1,0);
vv[i][0] = vv[i][vv[i].size() - 1] = 1;
}
for(int i = 0 ;i < vv.size(); i++)
{
for(int j = 0; j < vv[i].size(); j++)
{
if(vv[i][j] == 0)
{
vv[i][j] = vv[i-1][j-1] + vv[i-1][j];
}
}
}
return vv;
}
};
?文章來源:http://www.zghlxwxcb.cn/news/detail-835566.html
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?文章來源地址http://www.zghlxwxcb.cn/news/detail-835566.html
到了這里,關(guān)于leetcode | 楊輝三角 | 電話號碼配對的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!