264. Ugly Number II(丑数 剑指offer 34)
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)的更多相关文章
- 264 Ugly Number II 丑数 II
编写程序找第 n 个丑数.丑数就是只包含质因子 2, 3, 5 的正整数.例如, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 就是前10个丑数.注意:1. 1 一般也被当做丑数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 ...
- [LeetCode] 264. Ugly Number II 丑陋数之二
Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...
- Leetcode264. Ugly Number II丑数2
编写一个程序,找出第 n 个丑数. 丑数就是只包含质因数 2, 3, 5 的正整数. 示例: 输入: n = 10 输出: 12 解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 ...
- 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 ...
- 剑指 Offer 34. 二叉树中和为某一值的路径 + 记录所有路径
剑指 Offer 34. 二叉树中和为某一值的路径 Offer_34 题目详情 题解分析 本题是二叉树相关的题目,但是又和路径记录相关. 在记录路径时,可以使用一个栈来存储一条符合的路径,在回溯时将进 ...
- 剑指 Offer 34. 二叉树中和为某一值的路径
剑指 Offer 34. 二叉树中和为某一值的路径 输入一棵二叉树和一个整数,打印出二叉树中节点值的和为输入整数的所有路径.从树的根节点开始往下一直到叶节点所经过的节点形成一条路径. 示例: 给定如下 ...
- 【刷题-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】264. Ugly Number II
Ugly Number II Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose ...
随机推荐
- ubuntu16.04 安装 eclipse
1. 下载jdk , jdk-8u77-Linux-x64.tar.gz 2.下载 eclipse , eclipse-jee-mars-2-linux-gtk-x86_64.tar.gz 注:我下 ...
- ChemDraw Pro绘制无环链结构的两种方法
ChemDraw Pro 14是一款专门针对化学图形绘制而开发制作的编辑软件,是目前工科类常用的绘制化学结构工具,用于快速绘制常用的环结构组成.以下教程讲解ChemDraw Pro绘制无环链结构的两种 ...
- 判断ActiveX控件是Desgin Mode还是Runtime Mode
对于MFC COleControl::AmbientUserMode Determines if the Container is in design mode or user mode. BOOL ...
- 动态规划——最长公共上升子序列LCIS
问题 给定两个序列A和B,序列的子序列是指按照索引逐渐增加的顺序,从原序列中取出若干个数形成的一个子集,若子序列的数值大小是逐渐递增的则为上升子序列,若A和B取出的两个子序列A1和B1是相同的,则A1 ...
- XE10 塔建 Android 开发环境 (已测试通过)
XE10 塔建 Android 开发环境 1. E:\DevCSS\Android\adt-bundle-windows-x86-20131030\adt-bundle-windows-x86-201 ...
- python中的函数的执行分类
author:headsen chen date: 2018-03-21 17:42:13 notice:This article created by headsen chen himself ...
- Android 获取当前应用的版本号和当前系统的版本号
1.获取当前程序版本名 我们可以在AndroidManifest.xml中设置程序的版本号等,如android:versionName="1.0",那如果想在代码中获取这个版本号呢 ...
- Exchange Pause or stop transport service
The Microsoft Exchange Transport service is a service available both on the Microsoft Exchange Serve ...
- centos7常用命令集合
版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[+] CentOS7 常用命令集合 这两天一直在对CentOS 7.2进行初体验,各种学习命令肿么用,不过其实大多和DOS是一 ...
- 苏宁易购微信端 wx ios android other 通过js来控制样式
<!DOCTYPE HTML><html><head><meta charset="UTF-8"><meta name=&qu ...