Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<int> lexicalOrder(int n) {
  4. result.clear();
  5.  
  6. int i = 1;
  7. while (i <= n)
  8. {
  9. result.push_back(i);
  10. if (result.size() >= n)
  11. break;
  12. if (i * 10 <= n)
  13. {
  14. i *= 10;
  15. }
  16. else if (i % 10 != 9 && i + 1 <= n)
  17. {
  18. ++i;
  19. }
  20. else if (i>=10&&(i + 10) / 10 <= n)
  21. {
  22. while ((i / 10) % 10 == 9)
  23. i /= 10;
  24. i = i / 10 + 1;
  25. }
  26.  
  27. }
  28. return result;
  29. }
  30. int current = 1;
  31. vector<int> result;
  32. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement