Write a program to find the
n-th ugly number.
Ugly numbers are positive numbers whose prime factors only include
2, 3, 5.
Input: n = 10 Output: 12 Explanation:
1, 2, 3, 4, 5, 6, 8, 9, 10, 12is the sequence of the first
1is typically treated as an ugly number.
ndoes not exceed 1690.
- Merge k Sorted Lists (Hard)
- Count Primes (Easy)
- Ugly Number (Easy)
- Perfect Squares (Medium)
- Super Ugly Number (Medium)
Hint 1The naive approach is to call
isUglyfor every number until you reach the nth one. Most numbers are not ugly. Try to focus your effort on generating only the ugly ones.