Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
LRU_CACHE solution in Creative category for Ugly Numbers by U.V
from functools import lru_cache
@lru_cache
def ugly_number(n: int) -> int:
u = [1]
i = 0
#while len(u) <= n:
while i < 1500:
t = u[i]
i += 1
u.extend([t*2, t * 3, t * 5])
u = sorted(set(u))
#print(u[n-1], u[-50:])
return u[n-1]
Oct. 27, 2022
Comments: