1.打印从1到最大的n位数
https://leetcode-cn.com/problems/da-yin-cong-1dao-zui-da-de-nwei-shu-lcof/
考虑大数问题
class Solution {
public:
vector<int> nums;
string s;
vector<int> printNumbers(int n) {
s.resize(n,'0');
dfs(n,0);
return nums;
}
void dfs(int end,int index){
if(index==end){
save();
return;
}
for(int i=0;i<=9;i++){
s[index] = i+'0';
dfs(end,index+1);
}
}
void save(){
int ptr = 0;
while(ptr<s.size() && s[ptr]=='0') ptr++;
if(ptr!=s.size()) nums.push_back(stoi(s.substr(ptr)));
}
};
注:stoi : string 下的函数将字符串转换为数字