forked from DmrfCoder/AlgorithmAndDataStructure
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path32.py
28 lines (22 loc) · 687 Bytes
/
32.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# -*- coding:utf-8 -*-
class Solution:
def GetUglyNumber_Solution(self, index):
# write code here
if index==0:
return 0
t2Index = 0
t3Index = 0
t5Index = 0
res = [1]
for i in range(0, index - 1):
minValue = min(res[t2Index] * 2, min(res[t3Index] * 3, res[t5Index] * 5))
res.append(minValue)
if minValue == res[t2Index] * 2:
t2Index += 1
if minValue == res[t3Index] * 3:
t3Index += 1
if minValue == res[t5Index] * 5:
t5Index += 1
return res[-1]
s = Solution()
print s.GetUglyNumber_Solution(7)