Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- vector<int> lexicalOrder(int n) {
- result.clear();
- int i = 1;
- while (i <= n)
- {
- result.push_back(i);
- if (result.size() >= n)
- break;
- if (i * 10 <= n)
- {
- i *= 10;
- }
- else if (i % 10 != 9 && i + 1 <= n)
- {
- ++i;
- }
- else if (i>=10&&(i + 10) / 10 <= n)
- {
- while ((i / 10) % 10 == 9)
- i /= 10;
- i = i / 10 + 1;
- }
- }
- return result;
- }
- int current = 1;
- vector<int> result;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement