LeetCode Algorithm 386. 字典序排数
生活随笔
收集整理的這篇文章主要介紹了
LeetCode Algorithm 386. 字典序排数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
386. 字典序排數(shù)
Ideas
字典序排序嘛,先生成一個數(shù)字?jǐn)?shù)組,然后轉(zhuǎn)成字符串類型,再排一下序,之后再轉(zhuǎn)回整數(shù)數(shù)組,return就可以了。
Code
Python
from typing import Listclass Solution:def lexicalOrder(self, n: int) -> List[int]:num_list = list(range(1, n + 1))str_list = list(map(str, num_list))str_list.sort()return list(map(int, str_list))if __name__ == '__main__':print(Solution().lexicalOrder(13))總結(jié)
以上是生活随笔為你收集整理的LeetCode Algorithm 386. 字典序排数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2016年第七届蓝桥杯 - 省赛 - C
- 下一篇: 使用 Carla 和 Python 的自