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;
}
相关推荐
Book思议-8 分钟前
【数据结构实战】线性表的应用
c语言·数据结构·算法·链表
x_xbx35 分钟前
LeetCode:83. 删除排序链表中的重复元素
算法·leetcode·链表
xsyaaaan3 小时前
leetcode-hot100-链表
leetcode·链表
计算机安禾4 小时前
【C语言程序设计】第35篇:文件的打开、关闭与读写操作
c语言·开发语言·c++·vscode·算法·visual studio code·visual studio
CODE_RabbitV4 小时前
【3min 解决】keil5 编译stm32 出现一堆 core_cm3.c 报错问题
c语言·stm32·嵌入式硬件
weixin_537590455 小时前
《C程序语言设计》练习答案(练习1-3)
c语言·开发语言
爱编码的小八嘎5 小时前
C语言完美演绎4-10
c语言
逆境不可逃5 小时前
LeetCode 热题 100 之 33. 搜索旋转排序数组 153. 寻找旋转排序数组中的最小值 4. 寻找两个正序数组的中位数
java·开发语言·数据结构·算法·leetcode·职场和发展
leaves falling6 小时前
二分查找:迭代与递归实现全解析
数据结构·算法·leetcode
做怪小疯子6 小时前
Leetcode刷题——深度优先搜索(DFS)
算法·leetcode·深度优先