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
}
相关推荐
水木流年追梦9 小时前
大模型入门-Reward 奖励模型训练
开发语言·python·算法·leetcode·正则表达式
始三角龙17 小时前
LeetCode hoot 100 -- 缺失的第一个正整数
算法·leetcode·职场和发展
战南诚18 小时前
力扣 之 198.打家劫舍
python·算法·leetcode
李燚18 小时前
ReAct 循环的 50 行 Go 实现,逐行拆解
javascript·人工智能·react.js·golang·aigc·agent
_日拱一卒19 小时前
LeetCode:105从前序与中序遍历序列构造二叉树
算法·leetcode·职场和发展
ʚ希希ɞ ྀ20 小时前
dp反思与总结
算法·leetcode·动态规划
菜菜的顾清寒20 小时前
力扣Hot100(23)反转链表
算法·leetcode·链表
m0_6294947320 小时前
LeetCode 热题 100-----27. 合并两个有序链表
数据结构·算法·leetcode·链表
水木流年追梦20 小时前
大模型入门-RL基础
开发语言·python·算法·leetcode·正则表达式
念何架构之路21 小时前
Go pprof性能剖析
开发语言·后端·golang