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
}
相关推荐
天天向上10241 小时前
go 配置热更新
开发语言·后端·golang
LYFlied2 小时前
【每日算法】LeetCode 64. 最小路径和(多维动态规划)
数据结构·算法·leetcode·动态规划
Asus.Blogs2 小时前
SSE + Resty + Goroutine + Channel 完整学习笔记
笔记·学习·golang
sin_hielo3 小时前
leetcode 3074
数据结构·算法·leetcode
程序员-King.3 小时前
day124—二分查找—最小化数组中的最大值(LeetCode-2439)
算法·leetcode·二分查找
赴前尘4 小时前
golang获取一个系统中没有被占用的端口
开发语言·后端·golang
sandyznb4 小时前
go面试汇总
开发语言·面试·golang
im_AMBER5 小时前
Leetcode 85 【滑动窗口(不定长)】最多 K 个重复元素的最长子数组
c++·笔记·学习·算法·leetcode·哈希算法
2401_841495646 小时前
【LeetCode刷题】跳跃游戏Ⅱ
数据结构·python·算法·leetcode·数组·贪心策略·跳跃游戏
rannn_1117 小时前
【SQL题解】力扣高频 SQL 50题|DAY5
数据库·后端·sql·leetcode·题解