当前位置:网站首页>Sword finger offer 49. ugly number
Sword finger offer 49. ugly number
2022-07-24 19:27:00 【nsq1101】
subject
We will include only qualitative factors 2、3 and 5 The number of is called ugly (Ugly Number). Seek the order from small to large n Ugly number .
Example :
Input : n = 10
Output : 12
explain : 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 Before 10 Ugly number .
explain :
1 It's ugly .
n No more than 1690.
Ideas
- Dynamic programming
- 2,3,5 Multiple in , The smallest one now
Program
class Solution:
def nthUglyNumber(self, n: int) -> int:
dp = [1] * n
a,b,c=0,0,0
for i in range(1,n):
n2 = dp[a] * 2
n3 = dp[b] * 3
n5 = dp[c] * 5
dp[i] = min(n2,n3,n5)
if dp[i] ==n2: a = a+ 1
if dp[i] ==n3: b = b+ 1
if dp[i] ==n5: c = c+ 1
return dp[-1]
边栏推荐
- The ark compiler is coming. What about APK reinforcement
- Siyuan notes V2.1.2 synchronization problem
- Taokeeper environment setup
- Math
- PostgreSQL Elementary / intermediate / advanced certification examination (7.16) passed the candidates' publicity
- Convolutional neural network CNN
- MySQL (data types and integrity constraints)
- Pam4 popular science
- pyhanlp安装教程
- Install SSL Certificate in Litespeed web server
猜你喜欢

Analysis of the basic concept of digital warehouse

day 3

Pam4 popular science

Machine learning_ Softmax function (multi classification problem)

Common problems of multithreading and concurrent programming (to be continued)

Emergency lighting design of large stadiums and gymnasiums

Hidden Markov model HMM

Rotation matrix derivation process

湖仓一体释放全量数据价值,SequoiaDB v5.2线上发布会重磅来袭

Literature reading: gopose 3D human pose estimation using WiFi
随机推荐
Common methods of string class
Colon sorting code implementation
Pay close attention! List of the latest agenda of 2022 open atom open source Summit
MySQL version 5.7.9 SQL_ mode=only_ full_ group_ By question
Siyuan notes V2.1.2 synchronization problem
Tclsh array operation
Compressed string
Detailed explanation of ELF format (I)
Get module handle / base address
C language implementation of raii
Feature extraction tool transformer Bert
Using videoview to realize video playback in turns
湖仓一体释放全量数据价值,SequoiaDB v5.2线上发布会重磅来袭
Implement a proxy pool from 0
How to select the shelling tool?
Configmanager of unity framework [JSON configuration file reading and writing]
Mysql数据库,去重,连接篇
Day 9 (this keyword and experiment)
OpenGL learning (II) opengl rendering pipeline
[Huawei lyevk-3861a intelligent IOT development board evaluation] unpacking experience and Hisilicon hi3861v100 chip learning experience