In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
[Title Description]
Ugly number is a number that only have factors 2, 3 and 5.
Design an algorithm to find the nth ugly number. The first 10 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12...
Notice:Note that 1 is typically treated as an ugly number.
Design an algorithm to find the nth largest number containing only prime factors 2, 3, 5. The numbers that fit the criteria are: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12...
Note: we can think of 1 as an ugly number.
[Title Link]
http://www.lintcode.com/en/problem/ugly-number-ii/
[Title Analysis]
This is an extension of Merge Sort.
For any ugly number - K, 2*K, 3*K, and 5*K are ugly numbers, so new ugly numbers are generated by multiplying an existing ugly number by {2,3,5}.
if
Ugly Number: 1, 2, 3, 4, 5, 6, 8, 10, ..........
Then 1*2 2*2 3*2 4*2 5*2 6*2 8*2 10*2................................... 2
1*3 2*3 3*3 4*3 5*3 6*3 8*3 10*3 .......... *3
1*5 2*5 3*5 4*5 5*5 6*5 8*5 10*5 .......... *5
All are ugly numbers. Just keep adding the newly generated ugly number to the original ugly number array through merge sort until you find the Nth.
[Answer Link]
http://www.jiuzhang.com/solutions/ugly-number-ii/
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.