题目要求第n个丑数,所以对于中间结果不需要保存。
def Humble(index): curHum = 1 M2 = 2; M3 = 3; M5 = 5 while index > 1: curHum = min(min(M2, M3), M5) while M2 <= curHum: M2 *= 2 while M3 <= curHum: M3 *= 3 while M5 <= curHum: M5 *= 5 index -= 1 return curHum
【剑指offer】q34:丑数
时间: 2024-10-14 01:00:58