【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语义化
声明: 本文转载于:freeyiyi1993博客. 原文地址:http://www.cnblogs.com/freeyiyi1993/p/3615179.html 1.什么是HTML语义化? < ...
- Connect教程系列--响应式布局(一)
微软终于跨平台了,最近在第九频道(Event-Visual Studio)下面出来一系列关于vs2015的视频,介绍vs2015以及.NET5.0的新特性等,现针对其讲解的.NET和ASP.NET,进 ...
- C#函数式编程之部分应用
何谓函数式编程 相信大家在实际的开发中,很多情况下完成一个功能都需要借助多个类,那么我们这里的基本单元就是类.而函数式编程则更加细化,致使我们解决一个功能的基本单元是函数,而不是类,每个功能都是由多个 ...
- ASP.NET Core 源码阅读笔记(3) ---Microsoft.AspNetCore.Hosting
有关Hosting的基础知识 Hosting是一个非常重要,但又很难翻译成中文的概念.翻译成:寄宿,大概能勉强地传达它的意思.我们知道,有一些病毒离开了活体之后就会死亡,我们把那些活体称为病毒的宿主. ...
- JS学习笔记10_Ajax
1.Ajax概述 Asynchronous JavaScript + XML,支持js与服务器通信.在不unload页面的前提下从服务器获取新数据,以实现更好的用户体验(与传统的单击-等待交互不同的体 ...
- 移植到Windows CE 的经验
Windows CE 是微软早期推出的嵌入式设备和移动设备的开发运行平台,虽然目前移动端几乎都是android和ios的天下,但是,在嵌入式设备领域,Windows CE仍然占有一块地盘.很多用户希望 ...
- 自己动手写UI库——引入ExtJs(布局)
第一: 来看一下最终的效果 第二: 来看一下使用方法: 第三: Component类代码如下所示: public class Component { pub ...
- 选择哪种方式进行SharePoint的备份
关于SharePoint的备份还原功能,大家可能都有所了解.但是SharePoint一共有多少种备份方式呢,哪种备份方式是更适合你的呢,本文主要为大家梳理,并且深入的研究一下常见的几种备份方式,以便大 ...
- Java程序员的日常——经验贴(纯干货)
工作当中遇到的事情比较杂,因此涉及的知识点也很多.这里暂且记录一下,今天遇到的知识点,纯干货~ 关于文件的解压和压缩 如果你的系统不支持tar -z命令 如果是古老的Unix系统,可能并不认识tar ...
- atitit.编程语言 程序语言 的 工具性 和 材料性 双重性 and 语言无关性 本质
atitit.编程语言 程序语言 的 工具性 和 材料性 双重性 and 语言无关性 本质 #---语言的 工具和材料双重性 有的人说语言是个工具,有的人说语言是个材料..实际上语言同时属于两个属性. ...