Generate ugly numbers in a priority queue to get them in order solution in Clear category for Ugly Numbers by Phil15
from heapq import heappop, heappush
def ugly_number(n: int) -> int:
pqueue = 
added = set() # To not add a same number twice in "pqueue".
for _ in range(n):
lastest_ugly = heappop(pqueue) # Minimal ugly number in it.
nbs = 2 * lastest_ugly, 3 * lastest_ugly, 5 * lastest_ugly
for nb in nbs:
if nb not in added:
Dec. 8, 2021