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;
}
相关推荐
ElfBoard6 分钟前
ElfBoard技术贴|如何在ELF-RK3506开发板上构建AI编程环境
c语言·开发语言·单片机·嵌入式硬件·智能路由器·ai编程·嵌入式开发
枫叶丹412 分钟前
【Qt开发】Qt系统(八)-> Qt UDP Socket
c语言·开发语言·c++·qt·udp
Shirley~~17 分钟前
leetcode二分法
数据结构·算法·leetcode
程序猿编码21 分钟前
无状态TCP技术:DNS代理的轻量级实现逻辑与核心原理(C/C++代码实现)
c语言·网络·c++·tcp/ip·dns
Vallelonga28 分钟前
Rust 中 extern “C“ 关键字
c语言·开发语言·rust
Swift社区32 分钟前
LeetCode 378 有序矩阵中第 K 小的元素
算法·leetcode·矩阵
期货资管源码32 分钟前
智星期货资管子账户软件pc端开发技术栈的选择
c语言·数据结构·c++·vue
宵时待雨44 分钟前
数据结构(初阶)笔记归纳5:单链表的应用
c语言·开发语言·数据结构·笔记·算法
kklovecode1 小时前
数据结构---顺序表
c语言·开发语言·数据结构·c++·算法
sin_hielo1 小时前
leetcode 1292(二维前缀和)
数据结构·算法·leetcode