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.

丑数问题,这一第n个应该按照顺序来数,这样可以使用一个set来维护顺序,直到数到第n个丑数:

 class Solution {
public:
int nthUglyNumber(int n) {
set<long> ret;
long res;
ret.insert();
for(int i = ; i < n; ++i){
res = *ret.begin();
ret.insert(res * );
ret.insert(res * );
ret.insert(res * );
ret.erase(res);
}
return (int)res;
}
};

LeetCode OJ:Ugly Number II(丑数II)的更多相关文章

  1. LeetCode OJ:Ugly Number(丑数)

    Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers ...

  2. 264 Ugly Number II 丑数 II

    编写程序找第 n 个丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 就是前10个丑数.注意:1. 1 一般也被当做丑数2. ...

  3. LeetCode OJ 之 Ugly Number (丑数)

    题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive num ...

  4. [LeetCode]313. Super Ugly Number超级丑数,丑数系列看这一道就行了

    丑数系列的题看这一道就可以了 /* 和ugly number2差不多,不过这次的质因子多了,所以用数组来表示质因子的target坐标 target坐标指的是这个质因子此次要乘的前任丑数是谁 */ pu ...

  5. [LeetCode] Super Ugly Number 超级丑陋数

    Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all ...

  6. 313 Super Ugly Number 超级丑数

    编写一段程序来寻找第 n 个超级丑数.超级丑数是指其所有质因数都在长度为k的质数列表primes中的正整数.例如,[1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] ...

  7. 【easy】263. Ugly Number 判断丑数

    class Solution { public: bool isUgly(int num) { ) return false; ) return true; && num % == ) ...

  8. Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II)

    Leetcode之动态规划(DP)专题-264. 丑数 II(Ugly Number II) 编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n ...

  9. [LeetCode] 264. Ugly Number II 丑陋数 II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  10. [LeetCode]丑数 II&C++中priority_queue和unordered_set的使用

    [LeetCode]丑数 II&C++中priority_queue和unordered_set的使用 考虑到现实因素,LeetCode每日一题不再每天都写题解了(甚至有可能掉题目?--)但对 ...

随机推荐

  1. 关于TOSCA自动化测试工具, 我想问一些问题(持续整理中)

    通过学习,实践踩坑,有以下问题不太明白 1.  Artifacts and results from your complete test portfolio (cross-browser, mobi ...

  2. mellanox RDMA RoCE

    一:首先根据系统发行版本下载对应的驱动,下载地址如下: http://www.mellanox.com/page/products_dyn?product_family=26&mtag=lin ...

  3. linux 下各个头文件的作用[典]

    linux 下各个头文件的作用   2.6.30.4的头文件的位置和2.6.25.8的不一样,除去内核源码下的include目录外, 在arch/arm/mach-s3c2410/和arch/arm/ ...

  4. 如何快速生成openwrt的差异配置项

    答:./script/diff > defconfig 那么如何恢复添加的配置项呢? step 1:cat defconfig>>.config step 2:make defcon ...

  5. django中的分页设置

    1.在控制台中的展示 from django.core.paginator import Paginator iter = 'abcdefghijklmn' inator = Paginator(it ...

  6. 管理账号密码的工具-KeePass使用方法

    附件链接:https://files.cnblogs.com/files/stxs/KeePass.zip 打开压缩包“KeePass.zip",将文件"KeePass.exe&q ...

  7. LeetCode——remove-duplicates-from-sorted-list-ii

    Question Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only dist ...

  8. 解决"此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站"的问题

    在ASP.NET MVC项目中,使用AJAX向控制器发送GET请求获取JSON数据时,出现这个错误:"此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站.若要允许 G ...

  9. OKR学习总结

    OKR学习总结 背景:因为公司最近采用OKR工作法,所以来了解一下. 简介 OKR ——Object Key Results 主要分为两部分:O 和 KR ,就是目标和关键结果. 将这个丰满点描述,就 ...

  10. 解题报告:poj 3264 最基本的线段树

    2017-10-07 17:54:55 writer:pprp /* @theme: 最基本的线段树 @writer:pprp @end:17:38 @attention:记录的数组应该从1开始,不能 ...