def nthUglyNumber(self, n):
"""
:type n: int
:rtype: int
"""
l=[1]
primes=[2,3,5]
heapq.heapify(l)
set1=set(l)
n-=1
while n>0:
z=heapq.heappop(l)
n-=1
for i in primes:
if z*i not in set1:
heapq.heappush(l, z*i)
set1.add(z*i)
return heapq.heappop(l)
评论列表
文章目录