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
}
相关推荐
im_AMBER5 小时前
Leetcode 160 最小覆盖子串 | 串联所有单词的子串
开发语言·javascript·数据结构·算法·leetcode
帅小伙―苏7 小时前
力扣483找到字符串中所有字母异位词
算法·leetcode
smj2302_796826527 小时前
解决leetcode第3906题统计网格路径中好整数的数目
python·算法·leetcode
KobeSacre7 小时前
leetcode 树
算法·leetcode·职场和发展
conti1238 小时前
水题记录2.4
c++·笔记·题解
大大杰哥8 小时前
leetcode hot100(1) 哈希
leetcode
叹一曲当时只道是寻常8 小时前
memos-cli 安装与使用教程:将 Memos 笔记同步到本地并支持 AI 语义搜索
人工智能·笔记·golang
Engineer邓祥浩8 小时前
LeetCode 热题 100 - 第1题:两数之和
算法·leetcode·职场和发展
阿Y加油吧9 小时前
算法二刷复盘:LeetCode 79 单词搜索 & 131 分割回文串(Java 回溯精讲)
java·算法·leetcode
6Hzlia9 小时前
【Hot 100 刷题计划】 LeetCode 101. 对称二叉树 | C++ DFS 极简递归模板
c++·leetcode·深度优先