码迷,mamicode.com
首页 > 其他好文 > 详细

386.Lexicographical Numbers

时间:2018-10-04 09:30:40      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:lam   class   number   int   ace   example   list   rap   sel   

Given an integer n, return 1 - n in lexicographical order.

For example, given 13, return: [1,10,11,12,13,2,3,4,5,6,7,8,9].

Please optimize your algorithm to use less time and space. The input size may be as large as 5,000,000.

class Solution:
    def lexicalOrder(self, n):
        """
        :type n: int
        :rtype: List[int]
        """
        list = []
        for i in range(1,n+1):
            list.append(i)
        list.sort(key = lambda x:str(x))
        return list

386.Lexicographical Numbers

标签:lam   class   number   int   ace   example   list   rap   sel   

原文地址:https://www.cnblogs.com/bernieloveslife/p/9739725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!