package leetcode;

import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

/**
 * https://leetcode.com/problems/lexicographical-numbers/
 */
public class Problem386 {
    public List<Integer> lexicalOrder(int n) {
        TreeSet<Integer> result = new TreeSet<>((x, y) -> x.toString().compareTo(y.toString()));
        for (int i = 1; i <= n; i++) {
            result.add(i);
        }
        return new ArrayList<>(result);
    }

    public static void main(String[] args) {
        Problem386 prob = new Problem386();
        System.out.println(prob.lexicalOrder(13));
        System.out.println(prob.lexicalOrder(5000));
//        System.out.println(prob.lexicalOrder(5000000));
    }
}

@@ -66,34 +66,8 @@
 ist;
-%0Aimport java.util.TreeSet;
 %0A%0A/*
@@ -211,22 +211,19 @@
         
-TreeSe
+Lis
 t%3CIntege
@@ -242,110 +242,316 @@
 new 
-TreeSet%3C%3E((x, y) -%3E x.toString().compareTo(y.toString()));%0A        for (int i = 1; i %3C= n; i++) %7B%0A    
+ArrayList%3C%3E();%0A        for (int i = 1; i %3C= 9; i++) %7B%0A            lexicalOrder(n, %22%22 + i, result);%0A        %7D%0A        return result;%0A    %7D%0A%0A    private void lexicalOrder(int n, String accu, List%3CInteger%3E result) %7B%0A        int num = Integer.parseInt(accu);%0A        if (num %3E n) %7B%0A            return;%0A        %7D%0A
     
@@ -565,17 +565,19 @@
 ult.add(
-i
+num
 );%0A     
@@ -583,49 +583,95 @@
     
-%7D%0A        return new ArrayList%3C%3E(result);
+for (int i = 0; i %3C= 9; i++) %7B%0A            lexicalOrder(n, accu + i, result);%0A        %7D
 %0A   
@@ -867,18 +867,16 @@
 5000));%0A
-//
         

Update problem 386