https://leetcode.cn/problems/lexicographical-numbers/description/
想像成一颗树的遍历
AC代码:
class Solution {
public:
vector<int> lexicalOrder(int n) {
int cur = 1;
vector<int> ans(n);
for (int i = 0; i < n; i++)
{
ans[i] = cur;
if (cur * 10 <= n) {
cur *= 10;
}else {
while (cur == n || cur%10 == 9) {
cur /= 10;
}
cur++;
}
}
return ans;
}
};
标签:排数,LC,int,386,ans,cur
From: https://www.cnblogs.com/StarTwinkle/p/16913616.html