牛客网刷题:丑数
丑数_牛客网
https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b?tpId=13&tqId=11186&rp=2&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
解题思路:https://blog.csdn.net/weixin_37251044/article/details/89288546
# -*- coding:utf-8 -*-
class Solution:
def GetUglyNumber_Solution(self, index):
# write code here
if index == 0:
return 0
res = [1]
t2 = t3 = t5 = 0
cnt = 1
while cnt < index:
res.append(min(res[t2]*2, res[t3]*3, res[t5]*5))
if res[-1] == res[t2]*2:
t2 += 1
if res[-1] == res[t3]*3:
t3 += 1
if res[-1] == res[t5]*5:
t5 += 1
cnt += 1
return res[cnt-1]