当前位置:网站首页>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]
边栏推荐
- Data transmission of different fragments in the same activity
- JVM method call
- In the spring of domestic databases
- The ark compiler is coming. What about APK reinforcement
- Virbox compiler, which supports source code encryption of the whole platform and architecture
- [resolved] CVC datatype valid. 1.2.1: '' is not a valid value for 'ncname'.
- Sequences, time series and prediction in tessorflow quizs on coursera (I)
- MySQL8.0学习记录19 - 页区段与表空间
- Anaconda installs labelimg (super simple and available)
- [JVM learning 04] JMM memory model
猜你喜欢

High speed ASIC packaging trends: integration, SKU and 25g+
![[laser principle and application -6]:q switching element and Q drive circuit board](/img/30/e199b73fb9b0ad335f26f2378cfc45.png)
[laser principle and application -6]:q switching element and Q drive circuit board

FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 1)

Create a life cycle aware MVP architecture

FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 2)

Summary of articles in 2020

Convolutional Neural Networks in TensorFlow quizs on Coursera

Common methods of string class

Meshlab&PCL ISS关键点

Pam4 popular science
随机推荐
MySQL hidden version number
Convolutional Neural Networks in TensorFlow quizs on Coursera
[untitled]
OpenGL learning (III) glut two-dimensional image rendering
Day 4 (item 1: household income and expenditure records)
Mysql database, de duplication, connection
Description of large and small end mode
Meshlab&PCL ISS关键点
He has been in charge of the British Society of engineering and technology for 13 years, and van nugget officially retired
拦截器和过滤器
Hangdian multi School Game 1 question 3 backpack (XOR dp+bitset)
Cmake series tutorial 2 HelloWorld
Prevent static decompilation, dynamic debugging and plug-in
Colon sorting code implementation
FPGA 20 routines: 9. DDR3 memory particle initialization write and read through RS232 (Part 2)
Wireshark simple filter rule
Mysql8.0 learning record 19 - Page segments and tablespaces
MySQL8.0学习记录19 - 页区段与表空间
PCIe link initialization & Training
MySQL final chapter