# 264. 丑数 II

``` 1 //动态方程dp[i]=min(dp[p_2]*2,dp[p_3]*3,dp[p_5]*5)
2 class Solution
3 {
4 public:
5     int nthUglyNumber(int n)
6     {
7         vector<int> dp(n);
8         dp[0] = 1;
9         int p2,p3,p5;
10         p2 = p3 = p5 = 0;
11         for (int i = 1;i < n;++ i)
12         {
13             dp[i] = min(2 * dp[p2],min(3 * dp[p3],5 * dp[p5]));
14             if(dp[i] == 2 * dp[p2]) ++p2;
15             if(dp[i] == 3 * dp[p3]) ++p3;
16             if(dp[i] == 5 * dp[p5]) ++p5;
17         }
18         return dp.at(n-1);
19     }
20 };```

## [Swift]LeetCode264.丑数 II | 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. Example: Input: n = 10 Output: 12 Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note

## [LeetCode]70. Ugly Number II第N个丑数

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, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. Note that 1 is typically treated as an

## LeetCode(264):Ugly Number II

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. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.Note that 1 is typically