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

题目:

题解:

Go 复制代码
func lexicalOrder(n int) []int {
    ans := make([]int, n)
    num := 1
    for i := range ans {
        ans[i] = num
        if num*10 <= n {
            num *= 10
        } else {
            for num%10 == 9 || num+1 > n {
                num /= 10
            }
            num++
        }
    }
    return ans
}
相关推荐
Miraitowa_cheems2 小时前
LeetCode算法日记 - Day 84: 乘积为正数的最长子数组长度
数据结构·算法·leetcode·贪心算法·线性回归·深度优先·动态规划
xiaopengbc3 小时前
谷歌商店下载APK教程,先下载谷歌三件套,再直接从 Google Play 下载 APK 文件?
leetcode
水淹萌龙4 小时前
玩转 Go 表达式引擎:expr 实战指南
开发语言·后端·golang
Yeats_Liao5 小时前
Go Web 编程快速入门 07.4 - 模板(4):组合模板与逻辑控制
开发语言·后端·golang
Dream it possible!8 小时前
LeetCode 面试经典 150_链表_反转链表 II(60_92_C++_中等)(头插法)
c++·leetcode·链表·面试
nexttake9 小时前
5.go-zero集成gorm 和 go-redis
开发语言·后端·golang
py有趣10 小时前
LeetCode学习之实现strStr()
学习·算法·leetcode
夏鹏今天学习了吗10 小时前
【LeetCode热题100(52/100)】课程表
算法·leetcode·职场和发展
祁思妙想10 小时前
【LeetCode100】--- 101.重排链表【思维导图+复习回顾】
算法·leetcode·链表
Dream it possible!10 小时前
LeetCode 面试经典 150_链表_随机链表的复制(59_138_C++_中等)
c++·leetcode·链表