package leetcode;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

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

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

@@ -57,27 +57,20 @@
 va.util.
-Collections
+List
 ;%0Aimport
@@ -80,19 +80,22 @@
 va.util.
-Lis
+TreeSe
 t;%0A%0A/**%0A
@@ -237,19 +237,22 @@
         
-Lis
+TreeSe
 t%3CIntege
@@ -271,20 +271,64 @@
 new 
-ArrayList%3C%3E(
+TreeSet%3C%3E((x, y) -%3E x.toString().compareTo(y.toString())
 );%0A 
@@ -414,103 +414,38 @@
     
-Collections.sort(result, (x, y) -%3E x.toString().compareTo(y.toString()));%0A        return 
+return new ArrayList%3C%3E(
 result
+)
 ;%0A  
@@ -585,24 +585,79 @@
 Order(13));%0A
+        System.out.println(prob.lexicalOrder(5000));%0A//
         Syst

Update problem 386