本文主要是介绍力扣 264. 丑数 II python AC,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
堆
from heapq import heappop, heappushclass Solution:def nthUglyNumber(self, n):q = [1]vis = {1}for _ in range(n - 1):now = heappop(q)for i in [2, 3, 5]:if now * i not in vis:vis.add(now * i)heappush(q, now * i)return heappop(q)
这篇关于力扣 264. 丑数 II python AC的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!