LintCode Python 丑数II

class Solution:
    """
    @param {int} n an integer.
    @return {int} the nth prime number as description.
    """
    
    def nthUglyNumber(self, n):
        # write your code here
        L = [0, 1]
        while len(L)-1 < n:
            for i in L:
                if i*2 > L[-1]:
                    a = i*2
                    break
            for i in L:
                if i*3 > L[-1]:
                    b = i*3
                    break
            for i in L:
                if i*5 > L[-1]:
                    c = i*5
                    break
            L.append(min(a, b, c))
        return L[n]

你可能感兴趣的:(LintCode答案)