用了优先队列,还是超时

  1. class Solution {
  2. public:
  3. int nthSuperUglyNumber(int n, vector<int>& primes) {
  4. priority_queue<int,std::vector<int>,std::greater<int> > pq;
  5. pq.push(1);
  6. int i=1;
  7. int t;
  8. while(i<=n){
  9. if(t == pq.top())
  10. {
  11. pq.pop();
  12. continue;
  13. }
  14. t=pq.top();
  15. pq.pop();
  16. for(auto k:primes)
  17. pq.push(t*k);
  18. i++;
  19. // cout<<t<<" ";
  20. }
  21. return t;
  22. }
  23. };

  

LeetCode() Super Ugly Number的更多相关文章

  1. [LeetCode] Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  2. [LeetCode] Super Ugly Number (Medium)

    Super Ugly Number 最后WA没做出来. typedef long long int64; #define MAXBOUND 10000000 class Solution { publ ...

  3. [LeetCode] 313. Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  4. Leetcode 313. super ugly number

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  5. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  6. Super Ugly Number -- LeetCode

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  7. [LintCode] Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  8. 313. Super Ugly Number

    题目: Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose ...

  9. [Swift]LeetCode313. 超级丑数 | Super Ugly Number

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

随机推荐

  1. C# dll加载,抽象方法的使用

    抽象类! dll的使用 /// <summary> /// 返回类型--插件 /// </summary> /// <param name="baseName& ...

  2. 百度地图结合echarts并添加行政区块

    作者:LJaer链接:https://www.zhihu.com/question/49251513/answer/125728764来源:知乎<!DOCTYPE html> <ht ...

  3. install graph-tool

    try this if ubuntu version is >= 14.04 sudo apt-get update sudo apt-get upgrade sudo apt-get -y i ...

  4. 关于ajax跨域请求(cross Domain)

    Cross Domain AJAX主要就是A.com网站的页面发出一个XMLHttpRequest,这个Request的url是B.com,这样的请求是被禁止的,浏览器处于安全考虑不允许进行跨域访问, ...

  5. Java Json Object 互转

    官方网址: http://json-lib.sourceforge.net/ 需要准备的jar包 1. json-lib-2.4-jdk15.jar        目前最新版, 下载地址  http: ...

  6. ios开发之网络php

    接着前面的学习,几天上午学习了数据库网络值php用户的注册与登录,感觉代码与ios上的oc太相似了,因此学习下来没什么障碍了,下面是代码: 首先是javascript.html文件中: <!DO ...

  7. android开发虚拟机不能正常启动

    点击 window---perspective---DDMS---查看设备状态, 如果显示没有可用设备,则在AVD manager中重 启即可, 若列表中有设备,但显示offline  可采用一下方式 ...

  8. LeetCode 21 -- Merge Two Sorted Lists

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  9. js版扫雷(可直接运行试玩)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. 用 Express4 写一个简单的留言板

    Knowledge Dependence:阅读文本前,你需要熟悉 Node.js 编程.Express 以及相关工具和常用中间件的使用. Node.js 以其单线程异步非阻塞的特点,越来越被广大的 W ...