Git Product home page Git Product logo

Comments (1)

zhu733756 avatar zhu733756 commented on May 14, 2024

丑数哪一题 没必要加循环,可以简单判断最小的丑数包含几个2,3,5
def solution(index: int) -> int:
'''
1 -> 1
2 -> 2 12
3 -> 3 1
3
4 -> 4 22
5 -> 5 1
5
6 -> 6 23
7 -> 8 2
22
8 -> 9 3
3
9 -> 10 25
10 -> 12 2
23
11 -> 15 3
5
直接判断这个数里面分别包含几个2,3,5
'''
if index < 0:
return
ants = [1] * index
index2, index3, index5 = 0, 0, 0
for i in range(1,index):
ants[i] = min(ants[index2] * 2, ants[index3] * 3, ants[index5] * 5)
if ants[index2] * 2 == ants[i]:
index2 += 1
if ants[index3] * 3 == ants[i]:
index3 += 1
if ants[index5] * 5 == ants[i]:
index5 += 1
return ants[-1]

print(solution(11))

from algorithmsbypython.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.