Skip to content

Commit

Permalink
Update super-ugly-number.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Mar 29, 2018
1 parent 9a2ac6f commit fcf6541
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions C++/super-ugly-number.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Time: O(n * logk) ~ O(n * k)
// Time: O(n * k)
// Space: O(n + k)

// Heap solution. (308ms)
Expand All @@ -17,7 +17,7 @@ class Solution {
tie(uglies[i], k) = heap.top();
heap.pop();
ugly_by_last_prime[i] = k;
while (ugly_by_last_prime[++idx[k]] > k); // worst time: O(k)
while (ugly_by_last_prime[++idx[k]] > k); // average time: O(k)
heap.emplace(uglies[idx[k]] * primes[k], k);
}
return uglies[n - 1];
Expand Down

0 comments on commit fcf6541

Please sign in to comment.