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, and n does not exceed 1690.

 class Solution:

     def nthUglyNumber(self, n):
"""
:type n: int
:rtype: int
"""
l= []
l.append(1)
t2,t3,t5=0,0,0
mins = 0
while len(l)<n:
mins = min(l[t2]*2,l[t3]*3,l[t5]*5)
l.append(mins)
if(mins == l[t2]*2):
t2+=1
if(mins == l[t3]*3):
t3+=1
if(mins == l[t5]*5):
t5+=1
return l[-1]

264. Ugly Number II(丑数 剑指offer 34)的更多相关文章

  1. 264 Ugly Number II 丑数 II

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

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

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

  3. [LeetCode] 264. Ugly Number II 丑陋数之二

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

  4. Leetcode264. Ugly Number II丑数2

    编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 ...

  5. leetcode 263. Ugly Number 、264. Ugly Number II 、313. Super Ugly Number 、204. Count Primes

    263. Ugly Number 注意:1.小于等于0都不属于丑数 2.while循环的判断不是num >= 0, 而是能被2 .3.5整除,即能被整除才去除这些数 class Solution ...

  6. 剑指 Offer 34. 二叉树中和为某一值的路径 + 记录所有路径

    剑指 Offer 34. 二叉树中和为某一值的路径 Offer_34 题目详情 题解分析 本题是二叉树相关的题目,但是又和路径记录相关. 在记录路径时,可以使用一个栈来存储一条符合的路径,在回溯时将进 ...

  7. 剑指 Offer 34. 二叉树中和为某一值的路径

    剑指 Offer 34. 二叉树中和为某一值的路径 输入一棵二叉树和一个整数,打印出二叉树中节点值的和为输入整数的所有路径.从树的根节点开始往下一直到叶节点所经过的节点形成一条路径. 示例: 给定如下 ...

  8. 【刷题-LeetCode】264. Ugly Number II

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

  9. 【LeetCode】264. Ugly Number II

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

随机推荐

  1. SpringCloud服务发现(Eureka)简介

    Eureka是Netflix开发的服务发现框架,SpringCloud将它集成在自己的子项目spring-cloud-netflix中,实现SpringCloud的服务发现功能. 为什么要使用Eure ...

  2. hrbustoj 1305:多边形(计算几何,极角排序练习)

    多边形 Time Limit: 1000 MS     Memory Limit: 65536 K Total Submit: 113(42 users)   Total Accepted: 51(3 ...

  3. jQuery实现鼠标悬停显示提示信息窗口的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Js 的几种去重(一维)

    写的几种数组去重方法: 第一种: [利用排序方法,然后比较当前元素与下一个元素是否相等] function repeat1(arr) { var length = arr.length; var re ...

  5. LAMP环境搭建博客

    背景: 公司要用到lamp环境,让我装,我就开始着手找资料,一般分为源码装和yum装,源码装很容易出错,所以我选择了yum装,. 服务器:aliyun服务器  centos6.8系统 按照第一个安装完 ...

  6. THINKPHP5操作数据库代码示例

    数据库表结构 #表结构 CREATE TABLE `qrcode_file` ( `id` ) NOT NULL AUTO_INCREMENT, `active` ) ' COMMENT '是否有效' ...

  7. shell脚本学习总结12--系统信号

    信号是Linux系统中一种进程通信机制.我们可以使用特定的信号来中断进程.每一种信号都同一个整数值相关联. kill命令可用来想进程发送信号,而trap命令用来处理所接收的信号. kill 列出所有可 ...

  8. 170414、zookeeper和dubbo的关系

    Dubbo建议使用Zookeeper作为服务的注册中心. 1.   Zookeeper的作用:         zookeeper用来注册服务和进行负载均衡,哪一个服务由哪一个机器来提供必需让调用者知 ...

  9. Code Forces 645C Enduring Exodus

    C. Enduring Exodus time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

  10. SQL Server中执行Sql字符串,返回执行结果

    今天遇到一个问题:想把sql字符串在SQL Server 中执行了,并获取执行的结果 ); SET @tablename='select @table3 = count(1) from UserVis ...