313_super_ugly_number.py 文件源码

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

项目:Machine_Learning_Playground 作者: yao23 项目源码 文件源码
def nthSuperUglyNumber1(self, n, primes):
        """
        :type n: int
        :type primes: List[int]
        :rtype: int
        """
        uglies = [1]

        def gen(prime):
            for ugly in uglies:
                yield ugly * prime

        merged = heapq.merge(*map(gen, primes))
        while len(uglies) < n:
            ugly = next(merged)
            if ugly != uglies[-1]:
                uglies.append(ugly)
        return uglies[-1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号