264. Ugly Number II(丑数 剑指offer 34)
2024-09-03 06:03:41
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]
最新文章
- FCM聚类算法介绍
- session过期返回登录页面跳出frame
- jquery.validate:
- C#之XMAL与WPF
- aspx页面Page_Load和aspx页面上控件Page_Load事件执行顺序
- Python入门(二,基础)
- 功能:使用QQ号登陆,并加上微信和短信提醒,是否增量备份可选,阿里大鱼短信发送开发与测试,聚合数据(用JSON发短信,比较清楚)
- 关于Windows高DPI的一些简单总结(Window上一般默认是96 dpi 作为100% 的缩放比率)
- javascript requestAnimationFarme
- Oracle timestamp类型转换成date类型
- Signed Distance Field Shadow in Unity
- [EOJ Monthly 2018.10][C. 痛苦的 01 矩阵]
- vue插件 使用use注册Vue全局组件和全局指令
- vue 路由传参 params 与 query两种方式的区别
- protobuf for java
- python---redis缓存页面前戏之剖析render源码
- linux centos挂载数据盘教程
- 五种I/O模型和select函数简介
- java 多线程 2 Thread中start()和run()的区别
- 各种常用的JSON接口