@@ -0,0 +1,950 @@
+%22%22%22%0AGiven an integer n, return 1 - n in lexicographical order.%0A%0AFor example, given 13, return: %5B1,10,11,12,13,2,3,4,5,6,7,8,9%5D.%0A%0APlease optimize your algorithm to use less time and space. The input size may be%0Aas large as 5,000,000.%0A%22%22%22%0Aclass Solution(object):%0A    def lexicalOrder(self, n):%0A        %22%22%22%0A        :type n: int%0A        :rtype: List%5Bint%5D%0A        %22%22%22%0A        soln = %5BNone%5D * n%0A        curr = 1%0A        for i in range(n):%0A            soln%5Bi%5D = curr%0A            if curr * 10 %3C= n:%0A                curr *= 10%0A            else:%0A                if curr %3E= n:%0A                    curr //= 10%0A                curr += 1%0A                while curr %25 10 == 0:%0A                    curr //= 10%0A        return soln%0A%0A%0Aa = Solution()%0Aprint(a.lexicalOrder(13) == %5B1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9%5D)%0A%0A%22%22%22%0ANote: easy but expensive solution, not accepted%0A    def lexicalOrder(self, n):%0A        return sorted(%5Bi + 1 for i in range(n)%5D, key=str)%0A%22%22%22%0A

add 386