landscapemi的博客

# leetcode:数学： Ugly Number II（264）

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 ugly number.

class Solution {
public:
int nthUglyNumber(int n) {
vector<int> res(1, 1);
int i2 = 0, i3 = 0, i5 = 0;
while (res.size() < n) {
int m2 = res[i2] * 2, m3 = res[i3] * 3, m5 = res[i5] * 5;
int mn = min(m2, min(m3, m5));
if (mn == m2) ++i2;
if (mn == m3) ++i3;
if (mn == m5) ++i5;
res.push_back(mn);
}
return res.back();
}
};

#### [leetcode] 264. Ugly Number II 解题报告

2015-12-13 15:54:50

#### leetcode 264. Ugly Number II-丑数|动态规划

2016-06-11 14:41:41

#### [leetcode-264]Ugly Number II(java)

2015-08-24 11:12:50

#### leetcode 264: Ugly Number II

2015-08-23 10:53:33

#### [Leetcode 264] Ugly Number II

2015-09-02 00:23:05

#### [LeetCode] Ugly Number II

2015-08-21 22:26:46

#### LeetCode 264. Ugly Number II（丑数字）

2016-04-10 14:12:31

#### leetcode笔记：Ugly Number II

2016-01-10 18:42:23

#### [C++]Ugly Number II丑数2

2015-08-19 15:51:26

#### Ugly Number（丑数）系列题 Python解法

2016-05-08 14:27:16