利用三个指针
https://leetcode-cn.com/problems/ugly-number-ii/solution/cchou-shu-by-fu-xi-bei-kao-de-long-long/
class Solution:
def GetUglyNumber_Solution(self, index):
# write code here
if not index:
return 0
res = [1]
idx2 = 0
idx3 = 0
idx5 = 0
for i in range(index-1):
res.append(min(res[idx2]*2,res[idx3]*3,res[idx5]*5))
if res[-1] == res[idx2]*2:
idx2 += 1
if res[-1] == res[idx3]*3:
idx3 += 1
if res[-1] == res[idx5]*5:
idx5 += 1
return res[-1]
京公网安备 11010502036488号