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
}
相关推荐
小欣加油2 小时前
leetcode 面试题01.02判定是否互为字符重排
数据结构·c++·算法·leetcode·职场和发展
3Cloudream2 小时前
LeetCode 003. 无重复字符的最长子串 - 滑动窗口与哈希表详解
算法·leetcode·字符串·双指针·滑动窗口·哈希表·中等
林木辛7 小时前
LeetCode热题 42.接雨水
算法·leetcode
kite01218 小时前
Gin + Zap 日志:构建高性能、结构化的应用日志系统
golang·gin·log·zap
黑菜钟9 小时前
代码随想录第七天|● 454.四数相加II ● 383. 赎金信 ● 15. 三数之和 18.四数之和
c++·算法·leetcode
OxYGC10 小时前
[玩转GoLang] 5分钟整合Gin / Gorm框架入门
开发语言·golang·gin
pzx_00110 小时前
【LeetCode】14. 最长公共前缀
算法·leetcode·职场和发展
songx_9911 小时前
leetcode10(跳跃游戏 II)
数据结构·算法·leetcode
向上的车轮12 小时前
基于go语言的云原生TodoList Demo 项目,验证云原生核心特性
开发语言·云原生·golang
hansang_IR12 小时前
【题解】洛谷 P4286 [SHOI2008] 安全的航线 [递归分治]
c++·数学·算法·dfs·题解·向量·点积