您的位置:首页 > 其它

Leetcode刷题:386. Lexicographical Numbers

2018-03-23 15:09 477 查看
想到的是变成字符然后排序。

version 1 :

def lexicalOrder(self, n):
"""
:type n: int
:rtype: List[int]
"""
res=[]
for i in range(n+1):
res.append(str(i))
return map(lambda x: int(x),sorted(res)[1:])


version 2:

改进用到了sorted函数里的key

def lexicalOrder(self, n):
return sorted(range(1, n+1), key=str)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: