12min
def GetUglyNumber_Solution(self, index):
if index<1:return None
res=[1]
p2,p3,p5=0,0,0
for i in range(index):
tmp=min(res[p2]*2,res[p3]*3,res[p5]*5)
if tmp==res[p2]*2:p2+=1
if tmp==res[p3]*3:p3+=1
if tmp==res[p5]*5:p5+=1
res.append(tmp)
return res[index-1]
网友评论