文章目录
  1. 1. Lexicographical Numbers

Lexicographical Numbers


这道题目用递归来做,”10”<”100”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void helper(int start, int end, vector<int> &v)
{
if (start <= end)
{
v.push_back(start);
helper(start*10, end, v);
if (start+1 <= (start / 10) * 10 + 9)
helper(start+1,end,v);
}
}

vector<int> lexicalOrder(int n) {
vector<int> v;

helper(1, n, v);

return v;
}
文章目录
  1. 1. Lexicographical Numbers