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;
}
相关推荐
唐梓航-求职中11 小时前
技术-算法-leetcode-1606. 找到处理最多请求的服务器(易懂版)
服务器·算法·leetcode
4311媒体网12 小时前
C语言操作符全解析 C语言操作符详解
java·c语言·jvm
二年级程序员12 小时前
一篇文章掌握“顺序表”
c语言·数据结构
傻乐u兔13 小时前
C语言进阶————指针4
c语言·开发语言
历程里程碑13 小时前
Linux22 文件系统
linux·运维·c语言·开发语言·数据结构·c++·算法
YGGP14 小时前
【Golang】LeetCode 128. 最长连续序列
leetcode
2601_9491465320 小时前
C语言语音通知接口接入教程:如何使用C语言直接调用语音预警API
c语言·开发语言
月挽清风1 天前
代码随想录第十五天
数据结构·算法·leetcode
知南x1 天前
【Ascend C系列课程(高级)】(1) 算子调试+调优
c语言·开发语言
TracyCoder1231 天前
LeetCode Hot100(34/100)——98. 验证二叉搜索树
算法·leetcode