题目描述
把只包含质因子2、3和5的数称作丑数(Ugly Number)。例如6、8都是丑数,但14不是,因为它包含质因子7。 习惯上我们把1当做是第一个丑数。求按从小到大的顺序的第N个丑数。
解题思路
- 理解什么是丑数?
- 怎么计算丑数很重要
python 代码
# -*- coding:utf-8 -*-
class Solution:
def GetUglyNumber_Solution(self, index):
# write code here
res = []
for k in range(15):
for j in range(20):
for i in range(30):
res.append(2**i*3**j*5**k)
res.sort()
return res[index-1] if index else 0
s = Solution()
result = s.combinationSum(6)
print(result)