码迷,mamicode.com
首页 > 其他好文 > 详细

剑指Offer 49

时间:2019-06-14 14:34:51      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:==   style   odi   number   ext3   def   color   turn   next   

 1 # -*- coding:utf-8 -*-
 2 class Solution:
 3     def GetUglyNumber_Solution(self, index):
 4         if index <= 6:
 5             return index
 6         i2,i3,i5= 0,0,0
 7         dp = [0] * index
 8         dp[0] = 1
 9         for i in range(1,index):
10             next2 = dp[i2] * 2
11             next3 = dp[i3] * 3
12             next5 = dp[i5] * 5
13             dp[i] = min(next2,min(next3,next5))
14             if dp[i] == next2:
15                 i2 += 1
16             if dp[i] == next3:
17                 i3 += 1
18             if dp[i] == next5:
19                 i5 += 1
20         return dp[index-1]
21         # write code here

 

剑指Offer 49

标签:==   style   odi   number   ext3   def   color   turn   next   

原文地址:https://www.cnblogs.com/asenyang/p/11022941.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!