Ugly Number II
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5.
(第 n 个丑数)
Note:
- 1 is typically treated as an ugly number.
- n does not exceed 1690.
Example:
1. 动态规划
任何一个新的丑数可以看做是一个旧的丑数乘以 2,3,5 得到的。因此可以设置三个指针,每当因为乘以一个因子而增加一个丑数时,相应的指针就后移,具体实现过程如下:
1 | class Solution: |