zoukankan      html  css  js  c++  java
  • LeetCode() Super Ugly Number

    用了优先队列,还是超时

    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;
        }
    };
    

      

  • 相关阅读:
    awk
    tac
    cat
    less
    more
    head
    vim
    linux安装redis
    Redis for Python开发手册
    Python3.x标准模块库目录
  • 原文地址:https://www.cnblogs.com/yanqi110/p/5026148.html
Copyright © 2011-2022 走看看