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
}
相关推荐
圣保罗的大教堂1 小时前
leetcode 1855. 下标对中的最大距离 中等
leetcode
脱氧核糖核酸__5 小时前
LeetCode热题100——234.回文链表(两种解法)
c++·算法·leetcode·链表
生信研究猿6 小时前
leetcode 416. 分割等和子集
算法·leetcode·职场和发展
6Hzlia7 小时前
【Hot 100 刷题计划】 LeetCode 24. 两两交换链表中的节点 | C++ 精准指针舞步
c++·leetcode·链表
亿牛云爬虫专家8 小时前
Go爬虫进阶:如何优雅地在Colly框架中实现无缝代理切换?
爬虫·中间件·golang·爬虫代理·colly框架·代理切换·api提取
会编程的土豆9 小时前
洛谷题单 入门1 顺序结构(go语言)
开发语言·后端·golang·洛谷
jieyucx9 小时前
Go 语言 switch 条件语句详解
开发语言·c++·golang
初心未改HD9 小时前
Go语言defer机制深度解析
开发语言·golang
踩坑记录10 小时前
leetcode 92. 反转链表 II 区间反转(不是整条链表反转)
leetcode·链表
6Hzlia10 小时前
【Hot 100 刷题计划】 LeetCode 148. 排序链表 | C++ 归并排序自顶向下
c++·leetcode·链表