A Python solution used sort


  • 0
    A
    class Solution:
        def lexicalOrder(self, n):
            """
            :type n: int
            :rtype: List[int]
            """
            nums = [str(n) for n in range(1, n+1)]
            nums = sorted(nums)
            return [int(s) for s in nums]
    

Log in to reply
 

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