class Solution {
public:
int GetUglyNumber_Solution(int index) {
int cur1 = 0;
int cur2 = 0;
int cur3 = 0;
vector<int> tem;
int cur;
tem.push_back(1);
for (int i = 1; i <= index; i++) {
cur = min(min(tem[cur1] * 2, tem[cur2] * 3), tem[cur3] * 5);
tem.push_back(cur);
if (cur == tem[cur1] * 2)
cur1++;
if (cur == tem[cur2] * 3)
cur2++;
if(cur==tem[cur3]*5)
cur3++;
}
return tem[index - 1];
}
};
剑指offer 丑数
最新推荐文章于 2022-12-06 14:38:54 发布