Concise python solution

  • 0
    class Solution(object):
        def nthSuperUglyNumber(self, n, primes):
            primes_len = len(primes)
            ps = [0]*primes_len
            uglies = [1]
            for i in range(n-1):
                current_smallest = min([uglies[ps[j]]*primes[j] for j in range(primes_len)])
                for j in range(primes_len):
                    if current_smallest==uglies[ps[j]]*primes[j]:
                        ps[j] += 1
            return uglies[-1]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.