LintCode Python 丑数II

来源:互联网 发布:鞑靼牛肉 知乎 编辑:程序博客网 时间:2024/06/05 08:23
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]