JZ33丑数题的另一种思路
丑数
http://www.nowcoder.com/questionTerminal/6aa9e04fc3794f68acf8778237ba065b
大都是三指针解法,分享一种容易理解的思路吧,很好理解,懒得讲了。
# -*- coding:utf-8 -*- class Solution: def GetUglyNumber_Solution(self, index): # write code here if index <= 0: return 0 res = {1} cur = 1 for i in range(index): cur = min(res) res.remove(cur) res.add(cur * 2) res.add(cur * 3) res.add(cur * 5) return cur