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
}
相关推荐
To_OC6 小时前
LC 131 分割回文串:刚学回溯时,我连怎么切字符串都想不明白
javascript·算法·leetcode
旖-旎7 小时前
LeetCode 518:零钱兑换||(完全背包)—— 题解
c++·算法·leetcode·动态规划·背包问题
灯澜忆梦7 小时前
GO_并发编程---定时器
开发语言·后端·golang
To_OC7 小时前
LC 42 接雨水:暴力超时卡半天?前后缀数组一用就通了
javascript·算法·leetcode
qq_4523962316 小时前
第二篇:《Go 开发环境搭建:SDK、IDE、Module 与 Hello World》
开发语言·ide·golang
皓月斯语17 小时前
B3842 [GESP202306 三级] 春游 题解
数据结构·c++·算法·题解
tachibana218 小时前
hot100 数组中的第K个最大元素(215)
java·数据结构·算法·leetcode
晚笙coding20 小时前
LeetCode 98:验证二叉搜索树 —— 从局部判断到全局范围约束的递归思想
算法·leetcode·职场和发展
FellAveal20 小时前
【Go语言入门学习笔记】Part13.结构体与接口
笔记·学习·golang
microrain20 小时前
从设备孤岛到智能协同:SagooIoT场景联动实战解析
物联网·golang·sagooiot