264. Ugly Number II.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:Leetcode 作者: 95subodh 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号