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;
}
相关推荐
许愿与你永世安宁31 分钟前
力扣343 整数拆分
数据结构·算法·leetcode
爱coding的橙子33 分钟前
每日算法刷题Day42 7.5:leetcode前缀和3道题,用时2h
算法·leetcode·职场和发展
ruanjiananquan9936 分钟前
c,c++语言的栈内存、堆内存及任意读写内存
java·c语言·c++
持梦远方1 小时前
C 语言基础入门:基本数据类型与运算符详解
c语言·开发语言·c++
YuTaoShao1 小时前
【LeetCode 热题 100】73. 矩阵置零——(解法二)空间复杂度 O(1)
java·算法·leetcode·矩阵
Heartoxx1 小时前
c语言-指针(数组)练习2
c语言·数据结构·算法
杰克尼3 小时前
1. 两数之和 (leetcode)
数据结构·算法·leetcode
YuTaoShao4 小时前
【LeetCode 热题 100】56. 合并区间——排序+遍历
java·算法·leetcode·职场和发展
JoJo_Way8 小时前
LeetCode三数之和-js题解
javascript·算法·leetcode
码农不惑9 小时前
2025.06.27-14.44 C语言开发:Onvif(二)
c语言·开发语言