import java.util.*; public class Solution { public int GetUglyNumber_Solution(int index) { if (index < 7)return index; int[] res = new int[index]; res[0] = 1; int t2 = 0, t3 = 0, t5 = 0, i; for (i = 1; i < index; ++i) { res[i] = Math.min(res[t2] * 2, Math.min(res[t3] * 3, res[t5] * 5)); if (res[i] == res[t2] * 2)t2++; if (res[i] == res[t3] * 3)t3++; if (res[i] == res[t5] * 5)t5++; } return res[index - 1]; } }
第n个丑数
原创
©著作权归作者所有:来自51CTO博客作者GUUCIi的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
结构体:修改默认对齐数、结构体传参——《初学C语言第45天》
修改默认对齐数、结构体传参
修改默认对齐数 结构体传参 -
83 - 找到第n个丑数
找到第n个丑数
丑数 数组 -
达内课程-求第n个丑数
达内课程-求第n个丑数
丑数 java 最小值 i++ -
Python | 动态规划解决“返回第n个丑数”
本文首发于:"算法与编程之美",欢迎关注,及时了解更多此系列文章。问题描述给你一个整数n,请你找出并返回第n个丑数。丑数就是只包含质因数2、3和...
算法 leetcode 动态规划 编程语言 数据结构 -
LeetCode题解(0264):计算第N个丑数(Python)
题目:原题链接(中等)标签:数学、动态规划
leetcode python 数学 动态规划 时间复杂度 -
丑数丑数丑数
我们把只包含质因子 2、3 和 5 的数称作丑数(Ugly Number)。求按从小到大的顺序的第 n 个丑数。
算法 动态规划 c++ 丑数 Math