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
}
相关推荐
geovindu11 小时前
go: Mediator Pattern
设计模式·golang·中介者模式
Navigator_Z16 小时前
LeetCode //C - 1033. Moving Stones Until Consecutive
c语言·算法·leetcode
We་ct1 天前
LeetCode 72. 编辑距离:动态规划经典题解
前端·算法·leetcode·typescript·动态规划
m0_629494731 天前
LeetCode 热题 100-----17.缺失的第一个正数
数据结构·算法·leetcode
Tisfy1 天前
LeetCode 0796.旋转字符串:暴力模拟
算法·leetcode·题解·模拟·字符串匹配
小雅痞1 天前
[Java][Leetcode middle] 209. 长度最小的子数组
java·算法·leetcode
浅念-1 天前
吃透栈:LeetCode 栈算法题全解析
数据结构·c++·算法·leetcode·职场和发展·
阿Y加油吧1 天前
二刷 LeetCode:62. 不同路径 & 64. 最小路径和 复盘笔记
笔记·算法·leetcode
研究点啥好呢1 天前
滴滴Go后端开发工程师面试题精选:10道高频考题+答案解析
java·开发语言·golang
承渊政道1 天前
【动态规划算法】(两个数组的DP问题深度剖析与求解方法)
数据结构·c++·学习·算法·leetcode·动态规划·哈希算法