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
}
相关推荐
菜萝卜子5 小时前
【Go】新版GORM自动字段映射规则
数据库·golang
hweiyu005 小时前
IDEA搭建GO环境
开发语言·后端·golang·intellij-idea·idea·intellij idea
设计师小聂!6 小时前
力扣热题100------136.只出现一次的数字
数据结构·算法·leetcode
崎岖Qiu6 小时前
leetcode643:子数组最大平均数 I(滑动窗口入门之定长滑动窗口)
java·算法·leetcode·力扣·双指针·滑动窗口
flashlight_hi7 小时前
LeetCode 分类刷题:2824. 统计和小于目标的下标对数目
javascript·数据结构·算法·leetcode
Nejosi_念旧10 小时前
Go 函数选项模式
开发语言·后端·golang
এ᭄画画的北北11 小时前
力扣-11.盛最多水的容器
算法·leetcode
Eoneanyna11 小时前
go与grpc
开发语言·后端·golang
Dream it possible!13 小时前
LeetCode 面试经典 150_数组/字符串_O(1)时间插入、删除和获取随机元素(12_380_C++_中等)(哈希表)
c++·leetcode·面试·哈希表
快去睡觉~13 小时前
力扣137:只出现一次的数字Ⅱ
数据结构·算法·leetcode