264 Ugly Number II
264. Ugly Number II
1. Question
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, 8, 9, 10, 12
is the sequence of the first10
ugly numbers.
Note that1
is typically treated as an ugly number, and n does not exceed 1690.
2. Implementation
(1) Heap
3. Time & Space Complexity
Heap: 时间复杂度O(n * logn), 空间复杂度O(n)
Last updated