题目
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ac9e09cd27647ae4235078f932991ed0.png)
class Solution {
public:
vector<int> lexicalOrder(int n) {
vector<int>ans;
int cnt=0,now=1;
if(cnt<n) ans.push_back(now),++cnt;
while(cnt<n){
if(now*10<=n) now*=10;
else{
while(now%10==9||now==n) now/=10;
++now;
}
ans.push_back(now),++cnt;
}
return ans;
}
};
class Solution {
public:
vector<int> lexicalOrder(int n) {
vector<int>ans;
int cnt=0,now=1;
if(cnt<n) ans.push_back(now),++cnt;
while(1){
if(now*10<=n) now*=10;
else{
while(now%10==9||now==n) now/=10;
if(!now) break;
++now;
}
ans.push_back(now),++cnt;
}
return ans;
}
};