class Solution {
public:
int singleNumber(vector<int>& nums) {
int ret=0;
for(auto& ch:nums)
{
ret^=ch;
}
return ret;
}
};
class Solution {
public:
vector<vector<int>> generate(int numRows) {
vector<vector<int>> vv;
vv.resize(numRows);
for(int i=0;i<vv.size();i++)
{
vv[i].resize(i+1);
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;
}
};
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
int n=0;
for(int i=0;i<nums.size();i++)
{
if(nums[i]!=nums[n])
{
nums[++n]=nums[i];
}
}
return n+1;
}
};
部分递归展开图
class Solution {
public:
const char* arr[10]={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
void Combina(const string& digits,int i,string str,vector<string>& ret)
{
if(i==digits.size())
{
ret.push_back(str);
return;
}
int m=digits[i]-'0';
string s1=arr[m];
for(auto ch:s1)
{
Combina(digits,i+1,str+ch,ret);
}
}
vector<string> letterCombinations(const string& digits) {
vector<string> ret;
if(digits.empty())
return ret;
string str;
Combina(digits,0,str,ret);
return ret;
}
};