#include <cmath>
class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param index int整型
* @return int整型
*/
int GetUglyNumber_Solution(int index) {
// write code here
if(index<=0)
{
return 0;
}
vector<int> v;
v.resize(index,0);
int i=0;
v[0]=1;
int x=0;
int y=0;
int z=0;
while(i!=index-1)
{
v[i+1]=min(v[x]*2,min(v[y]*3,v[z]*5));
if(v[i+1]==v[x]*2)
{
x++;
}
if(v[i+1]==v[y]*3)
{
y++;
}
if(v[i+1]==v[z]*5)
{
z++;
}
i++;
}
return v[index-1];
}
};



京公网安备 11010502036488号