Python | Leetcode Python题解之第386题字典序排数

题目:

题解:

python 复制代码
class Solution:
    def lexicalOrder(self, n: int) -> List[int]:
        ans = [0] * n
        num = 1
        for i in range(n):
            ans[i] = num
            if num * 10 <= n:
                num *= 10
            else:
                while num % 10 == 9 or num + 1 > n:
                    num //= 10
                num += 1
        return ans
相关推荐
木井巳1 分钟前
【递归算法】找出所有子集的异或总和再求和
java·算法·leetcode·决策树·深度优先
不剪发的Tony老师3 分钟前
Spyder:一款面向数据科学的Python集成开发环境
ide·python
众创岛1 小时前
python中enumerate的用法
开发语言·python
布史1 小时前
Prometheus Python Client 实操指南:从零实现自定义 Exporter
网络·python·prometheus
纤纡.1 小时前
矿物识别分类:8 种机器学习算法对比与实战(平均值填充数据集)
python·深度学习·算法·机器学习
2301_818419011 小时前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
代码探秘者1 小时前
【算法篇】3.位运算
java·数据结构·后端·python·算法·spring
Aaswk1 小时前
回溯算法的本质理解
c语言·算法·leetcode·力扣·剪枝
迷海1 小时前
力扣原题《分发糖果》,采用二分原则,纯手搓,待验证
c++·算法·leetcode
`Jay1 小时前
Python Redis连接池&账号管理池
redis·分布式·爬虫·python·学习