技术栈

C语言 | Leetcode C语言题解之第264题丑数II

DdddJMs__1352024-07-26 15:42

题目:

题解:

cpp 复制代码
int nthUglyNumber(int n) {
    int dp[n + 1];
    dp[1] = 1;
    int p2 = 1, p3 = 1, p5 = 1;
    for (int i = 2; i <= n; i++) {
        int num2 = dp[p2] * 2, num3 = dp[p3] * 3, num5 = dp[p5] * 5;
        dp[i] = fmin(fmin(num2, num3), num5);
        if (dp[i] == num2) {
            p2++;
        }
        if (dp[i] == num3) {
            p3++;
        }
        if (dp[i] == num5) {
            p5++;
        }
    }
    return dp[n];
}
上一篇:【深度学习】大模型GLM-4-9B Chat ,微调与部署(3) TensorRT-LLM、TensorRT量化加速、Triton部署
下一篇:使用Django Rest Framework构建API
相关推荐
祈安_
2 天前
C语言内存函数
c语言·后端
norlan_jame
3 天前
C-PHY与D-PHY差异
c语言·开发语言
琢磨先生David
3 天前
Day1:基础入门·两数之和(LeetCode 1)
数据结构·算法·leetcode
czy8787475
3 天前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
m0_53123717
3 天前
C语言-数组练习进阶
c语言·开发语言·算法
超级大福宝
3 天前
N皇后问题:经典回溯算法的一些分析
数据结构·c++·算法·leetcode
Charlie_lll
3 天前
力扣解题-88. 合并两个有序数组
后端·算法·leetcode
菜鸡儿齐
3 天前
leetcode-最小栈
java·算法·leetcode
Frostnova丶
3 天前
LeetCode 1356. 根据数字二进制下1的数目排序
数据结构·算法·leetcode
Z9fish
4 天前
sse哈工大C语言编程练习23
c语言·数据结构·算法
热门推荐
01GitHub 镜像站点02【OpenClaw 本地实战 Ep.3】突破瓶颈:强制修改 openclaw.json 解锁 32k 上下文记忆03OpenClaw 使用和管理 MCP 完全指南04OpenClaw + 飞书(Feishu)环境搭建指南05Clawdbot部署教程:解决‘gateway token missing’授权问题的完整步骤06OpenClaw优化飞书API 额度已耗尽问题07Window 10部署openclaw报错node.exe : npm error code 12808Claude Code + GLM4.7 避坑指南:解决 Unable to connect to Anthropic services09OpenClaw 接入阿里云百炼 Coding Plan 指南10本地部署 OpenClaw + DeepSeek-R1 完全指南