C语言 | Leetcode C语言题解之第386题字典序排数

题目:

题解:

cpp 复制代码
int* lexicalOrder(int n, int* returnSize){
    int *ret = (int *)malloc(sizeof(int) * n);
    int number = 1;
    for (int i = 0; i < n; i++) {
        ret[i] = number;
        if (number * 10 <= n) {
            number *= 10;
        } else {
            while (number % 10 == 9 || number + 1 > n) {
                number /= 10;
            }
            number++;
        }
    }
    *returnSize = n;
    return ret;
}
相关推荐
csdn_aspnet21 分钟前
C语言 (QuickSort using Random Pivoting)使用随机枢轴的快速排序
c语言·算法·排序算法
语戚40 分钟前
力扣 494. 目标和 —— 回溯 & 动态规划双解法全解(Java 实现)
java·算法·leetcode·动态规划·力扣·dp·回溯
北顾笙9801 小时前
day23-数据结构力扣
数据结构·算法·leetcode
爱编码的小八嘎1 小时前
C语言完美演绎7-15
c语言
田梓燊1 小时前
leetcode 234
算法·leetcode·职场和发展
孬甭_1 小时前
揭开指针的面纱(下)
c语言
计算机安禾1 小时前
【数据结构与算法】第43篇:Trie树(前缀树/字典树)
c语言·开发语言·矩阵·排序算法·深度优先·图论·宽度优先
yashuk1 小时前
C语言入门教程:程序结构与算法举例
c语言·算法·教程·程序设计·开发过程
hanbr1 小时前
每日一题day1(Leetcode 76最小覆盖子串)
算法·leetcode
代码地平线1 小时前
C语言实现堆与堆排序详解:从零手写到TopK算法及时间复杂度证明
c语言·开发语言·算法