c++


  • 0
    H
    vector<int> lexicalOrder(int n) {
    	vector<int> res;
    	int cur = 1;
    	while (res.size() < n) {
    		res.push_back(cur);
    		if (cur * 10 <= n) {
    			cur *= 10;
    		}
    		else if (cur % 10 == 9 ||cur==n) {
    			while ((cur % 10 == 9) || cur == n) {
    				cur /= 10;
    			}
    			cur += 1;
    		}
    		else cur++;
    	}
    	return res;
    }
    

Log in to reply
 

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