题解 | #丑数#
丑数
http://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b
# -*- coding:utf-8 -*- class Solution: def GetUglyNumber_Solution(self, index): # write code here if index <= 0: return 0 uglyList = [1] p2, p3, p5 = 0, 0, 0 for i in range(index-1): curr = [uglyList[p2]*2, uglyList[p3]*3, uglyList[p5]*5] newUgly = min(curr) uglyList.append(newUgly) if newUgly%2 == 0: p2 += 1 if newUgly%3 == 0: p3 += 1 if newUgly%5 == 0: p5 += 1 print(curr, newUgly, uglyList) return uglyList[index-1]