313. Super Ugly Number

use generator to save storage and speed up program 

class Solution(object):
    def nthSuperUglyNumber(self, n, primes):
        """
        :type n: int
        :type primes: List[int]
        :rtype: int
        """
        uglies=[1]
        
        def gen(prime):
            for ugly in uglies:
                yield ugly*prime 
                
        #*unpack the list of generators         
        merged=heapq.merge(*map(gen,primes))
        
        while len(uglies)

你可能感兴趣的:(313. Super Ugly Number)