c++ 259 ms easy to understand


  • 0
    A
    class Solution {
    public:
        vector<int> lexicalOrder(int n) {
            int cnt = 0;
            int a = 1;
            vector<int> res(n);
            while(cnt<n)
            {
                res[cnt++] = a;
                a*=10; 
                while(a>n)
                {
                    a/=10;
                    a++;
                    while(a%10==0) a/=10;
                }
            }
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.