class Solution {
public:
int res;
priority_queue<int,vector<int>,greater<int>> minheap;
unordered_set<int> s;//所有出现过的丑数放在集合中
int getUglyNumber(int n) {
minheap.push(1);
while(s.size()<n)
{
res=minheap.top();minheap.pop();
if(s.count(res)) continue;//第一次遇到一个丑数时才拓展
s.insert(res);
minheap.push(res*2);
minheap.push(res*3);
minheap.push(res*5);
}
return res;
}
};
标签:丑数,set,greater,int,queue,minheap
From: https://www.cnblogs.com/tangxibomb/p/17352678.html