题解 | #字符串的排列#
丑数
http://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b
-- coding:utf-8 --
class Solution: def GetUglyNumber_Solution(self, index): # write code here ret = [] ret.append(1) x, y, z = 0, 0, 0 if index == 0: return 0 if index == 1: return ret[0] for i in range(1, index): nxt = min(ret[x]*2, ret[y]*3, ret[z]*5) if nxt == ret[x]*2: x += 1 if nxt == ret[y]*3: y += 1 if nxt == ret[z]*5: z += 1 ret.append(nxt)
print(i, nxt, x, y, z)
return ret[index-1]