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;
}
相关推荐
LDR0066 天前
Type-C 快充全面升级!LDR6601 赋能个人护理便携电机,重塑剃须刀 / 理发器新体验
c语言·开发语言
Luminous.6 天前
C语言--day30
c语言·开发语言
玖玥拾6 天前
C/C++ 数据结构(七)栈、容器适配器
c语言·数据结构·c++··容器适配器
謓泽6 天前
C语言不是语法,是通往机器的地图。
c语言·开发语言
不会C语言的男孩6 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
2601_951643886 天前
C语言长文整理,关键字和数据类型
c语言·数据类型·关键字·嵌入式开发·格式化输出
想吃火锅10056 天前
【leetcode】121.买卖股票的最佳时机js/c++
算法·leetcode·职场和发展
m0_547486666 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
✎ ﹏梦醒͜ღ҉繁华落℘6 天前
编程基础 --高内聚,低耦合
c语言·单片机
凌波粒6 天前
LeetCode--491.递增子序列(回溯算法)
数据结构·算法·leetcode