class Solution {
public:
int nthUglyNumber(int n) {
priority_queue<long ,vector<long>,greater<long>>q;
q.push(1);
for(int i =1;i<=n-1;i++){
long top =q.top();
while(!q.empty() && q.top()==top)
q.pop();
q.push(top*2);
q.push(top*3);
q.push(top*5);
}
return q.top();
}
};```
264. 丑数 II(优先队列)
最新推荐文章于 2022-10-01 20:19:31 发布