用了优先队列,还是超时
class Solution {
public:
int nthSuperUglyNumber(int n, vector<int>& primes) {
priority_queue<int,std::vector<int>,std::greater<int> > pq;
pq.push(1);
int i=1;
int t;
while(i<=n){
if(t == pq.top())
{
pq.pop();
continue;
}
t=pq.top();
pq.pop();
for(auto k:primes)
pq.push(t*k);
i++;
// cout<<t<<" ";
}
return t;
}
};
转载于:https://www.cnblogs.com/yanqi110/p/5026148.html
相关资源:数据结构—成绩单生成器