电话号码的字母组合
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())//结束条件
{
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;
}
};
文章来源:https://www.toymoban.com/news/detail-835566.html
文章来源地址https://www.toymoban.com/news/detail-835566.html
到了这里,关于leetcode | 杨辉三角 | 电话号码配对的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!