【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 treated as an ugly number.
Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.
思路:所有的ugly number都是由1开始,乘以2/3/5生成的。
只要将这些生成的数排序即可获得,自动排序可以使用set
这样每次取出的第一个元素就是最小元素,由此再继续生成新的ugly number.
class Solution {
public:
int nthUglyNumber(int n) {
set<long long> order;
order.insert();
int count = ;
long long curmin = ;
while(count < n)
{
curmin = *(order.begin());
order.erase(order.begin());
order.insert(curmin * );
order.insert(curmin * );
order.insert(curmin * );
count ++;
}
return (int)curmin;
}
};

【LeetCode】264. Ugly Number II的更多相关文章
- 【LeetCode】264. Ugly Number II 解题报告(Java & Python)
标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ https://leetcode.com/prob ...
- 【Leetcode】264. Ugly Number II ,丑数
原题 Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime facto ...
- 【刷题-LeetCode】264. Ugly Number II
Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...
- 【LeetCode】137. Single Number II 解题报告(Python)
[LeetCode]137. Single Number II 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/problems/single- ...
- 【LeetCode】263. Ugly Number 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 除去2,3,5因子 日期 [LeetCode] 题目 ...
- 【LeetCode】263. Ugly Number
Ugly Number Write a program to check whether a given number is an ugly number. Ugly numbers are posi ...
- 【LeetCode】137. Single Number II (3 solutions)
Single Number II Given an array of integers, every element appears threetimes except for one. Find t ...
- 【leetcode】1201. Ugly Number III
题目如下: Write a program to find the n-th ugly number. Ugly numbers are positive integers which are div ...
- 【LeetCode】137. Single Number II
题目: Given an array of integers, every element appears three times except for one. Find that single o ...
随机推荐
- 搜索结果高亮显示(不改变html标签)
分类: 代码2010-02-28 13:44 1574人阅读 评论(3) 收藏 举报 htmlinputstring 一.问题的产生 搜索结果高亮显示,在新闻标题,来源之类的地方好做,只需要用st ...
- WinForm动态添加控件及其事件(转)
出处:http://blog.sina.com.cn/s/blog_60d576800100tf61.html 1 private void PhotoForm_Load(object ...
- MySQL大小写敏感说明
Linux环境下,不是windows平台下.区别很大.注意. 一图胜千言 mysql> show create table Ac; +-------+-------------------- ...
- 状态伪类选择器(E::selection)
E::selection选择器: E::selection{background:#FF6600; color:#fff;} //当文字被选中时,背景是红色,文字是白色 E::-moz-s ...
- js的变量使用<bean><list:write>赋值时需加' '
script的变量使用<bean><list:write>赋值时需加' ',如:var code ='<bean:write name="target" ...
- 更改vsts源代码绑定服务器地址方法
第一步找到更改源代码管理 第二步首先选中第一个,滚动条拉至最后一项,点击最后一项(全选). 第三步点击绑定,vsts会自动签出所有项目,而后签入就可以更改成功了.
- JS DOM操作
一.DOM基础 1.节点(node)层次 Document--最顶层的节点,所有的其他节点都是附属于它的. DocumentType--DTD引用(使用<!DOCTYPE>语法)的对象表现 ...
- 大熊君说说JS与设计模式之------中介者模式Mediator
一,总体概要 1,笔者浅谈 我们从日常的生活中打个简单的比方,我们去房屋中介租房,房屋中介人在租房者和房东出租者之间形成一条中介.租房者并不关心他租谁的房.房东出租者也不关心他租给谁.因为有中介的存在 ...
- AutoMapper在ABP框架中的使用说明
为了说明AutoMapper如何使用,我专门开设了一个专题来讲,如果您还没有查看该专题,请点击这里.既然系统地学习了AutoMapper,那么接下来就是该用它实战的时候了.今天,我们就来揭开AutoM ...
- Eclipse在线安装SVN
一.SVN在线安装 下面为在线安装SVN插件.以下是在线安装步骤: 其中http://subclipse.tigris.org/update_1.10.x是最新版本的SVN插件的下载站点[subcli ...