leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0386.cpp (444B)


      1 class Solution {
      2   public:
      3     vector<int> lexicalOrder(int n) {
      4         vector<int> res(n);
      5         int cur = 1;
      6         for (int i = 0; i < n; i++) {
      7             res[i] = cur;
      8             if (cur * 10 <= n)
      9                 cur *= 10;
     10             else {
     11                 if (cur >= n) cur /= 10;
     12                 cur += 1;
     13                 while (cur % 10 == 0)
     14                     cur /= 10;
     15             }
     16         }
     17         return res;
     18     }
     19 };