用了优先队列,还是超时class Solution {public: int nthSuperUglyNumber(int n, vector& primes) { priority_queue,std::greater > pq; pq.push(1); int i=1; i...
分类:
其他好文 时间:
2015-12-07 15:49:09
阅读次数:
135
https://leetcode.com/problems/ugly-number-ii/第N个丑数,用暴力法导致,从1开始逐个验证是否是丑数,然后一直到找到第N个丑数,这个方法会超时。因为,当数字增大到一定的情况的时候,每个丑数之间的间隔是以指数倍增加的,导致了遍历的方法会在 i++ 的过程中耗费...
分类:
其他好文 时间:
2015-12-05 19:13:18
阅读次数:
139
题目:Write a program to find then-th ugly number.Ugly numbers are positive numbers whose prime factors only include2, 3, 5. For example,1, 2, 3, 4, 5, 6...
分类:
其他好文 时间:
2015-12-05 07:12:25
阅读次数:
179
题目连接https://leetcode.com/problems/ugly-number-ii/Ugly Number IIDescriptionWrite a program to find the $n_{th}$ ugly number.Ugly numbers are positive n...
分类:
其他好文 时间:
2015-12-04 22:43:05
阅读次数:
167
题目:Write a program to find the nth super ugly number.Super ugly numbers are positive numbers whose all prime factors are in the given prime list prime...
分类:
其他好文 时间:
2015-12-04 22:38:18
阅读次数:
118
题目:Write a program to find the n-th ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5...
分类:
其他好文 时间:
2015-12-04 22:34:42
阅读次数:
163
题目连接https://leetcode.com/problems/ugly-number/Ugly NumberDescriptionWrite a program to check whether a given number is an ugly number.Ugly numbers are...
分类:
其他好文 时间:
2015-12-04 22:32:20
阅读次数:
210
TLE解法:public class Solution { public int nthUglyNumber(int n) { int count = 0; int i = 1; while(count l1 = new LinkedList(); ...
分类:
其他好文 时间:
2015-12-04 00:58:30
阅读次数:
170
思路和ugly2一样,不过是变成了一组factor,用一个priority求出每次最小的,同时维护一个conut数组,记录每个factor走的次数有一个500000的过不了,超限了,无耻的写了一行作弊的代码public class Solution { public int nthSuperU...
分类:
其他好文 时间:
2015-12-03 09:54:41
阅读次数:
119
一个别人,非常牛逼的思路,膜拜了!orz!!!! vector results (1,1); int i = 0, j = 0, k = 0; while (results.size() < n) { results.push_bac...
分类:
其他好文 时间:
2015-11-29 23:09:02
阅读次数:
241