- 浏览: 183678 次
- 性别:
- 来自: 济南
文章分类
最新评论
Write a program to find the nth super ugly number.
Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4.
Note:
(1) 1 is a super ugly number for any given primes.
(2) The given numbers in primes are in ascending order.
(3) 0 < k ≤ 100, 0 < n ≤ 10^6, 0 < primes[i] < 1000.
类似Ugly number二,创建长度为n的数组,依次生成n个ugly number。代码如下:
Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes of size k. For example, [1, 2, 4, 7, 8, 13, 14, 16, 19, 26, 28, 32] is the sequence of the first 12 super ugly numbers given primes = [2, 7, 13, 19] of size 4.
Note:
(1) 1 is a super ugly number for any given primes.
(2) The given numbers in primes are in ascending order.
(3) 0 < k ≤ 100, 0 < n ≤ 10^6, 0 < primes[i] < 1000.
类似Ugly number二,创建长度为n的数组,依次生成n个ugly number。代码如下:
public class Solution { public int nthSuperUglyNumber(int n, int[] primes) { int[] count = new int[primes.length]; int[] result = new int[n]; result[0] = 1; int index = 1; while(index < n) { int min = Integer.MAX_VALUE; for(int i = 0; i < count.length; i++) { if(min > result[count[i]] * primes[i]) min = result[count[i]] * primes[i]; } result[index ++] = min; for(int i = 0; i < count.length; i++) { if(min == result[count[i]] * primes[i]) count[i] ++; } } return result[n - 1]; } }
发表评论
-
498. Diagonal Traverse
2019-11-15 13:52 265Given a matrix of M x N eleme ... -
496 Next Greater Element I
2019-11-14 13:50 267You are given two arrays (witho ... -
Word Break II
2016-03-09 03:15 384Given a string s and a dictiona ... -
Insert Interval
2016-03-08 02:11 374Given a set of non-overlapping ... -
Merge Intervals
2016-03-07 05:25 499Given a collection of intervals ... -
Merge k Sorted Lists
2016-03-07 04:03 563Merge k sorted linked lists and ... -
Multiply Strings
2016-03-06 07:27 475Given two numbers represented a ... -
N-Queens II
2016-03-06 03:06 664Follow up for N-Queens problem. ... -
N-Queens
2016-03-06 02:47 469The n-queens puzzle is the prob ... -
First Missing Positive
2016-03-05 03:09 430Given an unsorted integer array ... -
Spiral Matrix
2016-03-04 03:39 575Given a matrix of m x n element ... -
Trapping Rain Water
2016-03-04 02:54 581Given n non-negative integers r ... -
Repeated DNA Sequences
2016-03-03 03:10 426All DNA is composed of a series ... -
Increasing Triplet Subsequence
2016-03-02 02:48 898Given an unsorted array return ... -
Maximum Product of Word Lengths
2016-03-02 01:56 930Given a string array words, fin ... -
LRU Cache
2016-02-29 10:37 602Design and implement a data str ... -
Longest Increasing Path in a Matrix
2016-02-29 05:56 845Given an integer matrix, find t ... -
Coin Change
2016-02-29 04:39 783You are given coins of differen ... -
Minimum Height Trees
2016-02-29 04:11 706For a undirected graph with tre ... -
Bulb Switcher
2016-02-28 12:12 427There are n bulbs that are init ...
相关推荐
各种数据结构、算法及实用的C#源代码 C#,超级阿格里数字(超级丑数,Super Ugly Number)的算法与源...超级阿格里数字(超级丑数,Super Ugly Number)由丑数(Ugly Number)拓展而来,不过其因子质数,是事先给定的。
各种数据结构、算法及实用的C#源代码.C#,阿格里数(Ugly Number)的多种算法与源代码 阿格里数,即丑数(Ugly Number)、逊数(Humble Number)。 一般而言:把只包含质因子2,3和5的数称作丑数(Ugly Number)。...
The number of questions is increasing recently. Here is the classification of all `468` questions. For more questions and solutions, you can see my [LintCode](https://github.com/kamyu104/LintCode) ...
算法与数据结构它们分别涵盖了以下主要内容: 数据结构(Data Structures): 逻辑结构:描述数据元素之间的逻辑关系,如线性结构(如数组、链表)、树形结构(如二叉树、堆、B树)、图结构(有向图、无向图等)...
"gstreamer-plugins-ugly" 是 GStreamer 插件集合的一部分,专门用于处理可能不那么常见或者有版权争议的媒体格式,比如 MP3 音频编码。 MP3(MPEG-1 Audio Layer III)是一种广泛使用的音频压缩格式,它通过丢弃人...
【标题】:“EmailTemplaterGradle:SUPER HACKY UGLY LEAKY JavaFX 修补” 这个项目标题暗示了一个使用Gradle构建的JavaFX应用程序,名为“EmailTemplaterGradle”,它可能是一个用于创建和管理电子邮件模板的工具...
pku acm1338 Ugly Numbers 代码 动态规划思想,采用链表实现,解题报告请访问:http://blog.csdn.net/china8848
AutoJs源码-wzry.ugly.min.ugly.min.ugly.min.ugly.min.ugly.min.ugly.min。本资源购买前提醒:本源码都是实际autojs项目模板,安装好autojs直接运行即可打开。1、支持低版本autojs。2、资源仅供学习与参考,请勿...
pku acm 1338 Ugly Numbers代码 动态规划思想,数组实现 解题报告请访问:http://blog.csdn.net/china8848
scala-cli-maven-ugly-number 描述 将数字除以2、3和5的最大可除幂,如果数字变为1,则它是一个丑陋的数字,否则不是。 科技栈 OpenJDK的8 Scala 专家 Docker堆栈 docker-cli openjdk:8 要求 必须安装Docker桌面...
资源来自pypi官网。 资源全名:augly-0.1.9-py3-none-any.whl
scala-cli-sbt-ugly-number-pattern-match描述将数字除以2、3和5的最大可除幂,如果数字变为1,则它是一个丑陋的数字,否则不是。 遵循函数式编程实践。 模式匹配的示例。科技栈OpenJDK的8 ScalasbtDocker堆栈docker...
这两天在弄linux下的东西,用的是RedHat EnterPrise 6,但由于其yum源是收费的,就使用的是对应的CentOS6,但更新后发觉安装音乐解码器插件时还是差了这几个包,纠结了好久,终于找齐了,一并传上来,希望能帮到有...
1201.Ugly-Number-III(待定) (H) (男) (H) Binary Search by Value (男) (H-) (H-) (H) (H-) (H-) (H) (H-) (H-) (H) (H-) (H-) (男) (男) (H-) (M+) (男) (M+) (男) (M+) (H-) (M+
文章标题为《The Good, The Bad, and the Ugly, The UNIX Legacy》,副标题为“专家观点:UNIX的美与丑!”这份文档由贝尔实验室的罗布·派克(Rob Pike)撰写,他在文中探讨了UNIX操作系统的发展历程及其对现代计算...
10. **自我认知与转变**:故事最后,丑小鸭发现自己是一只美丽的天鹅,展示了自我认知的变化,同时也教授了形容词“ugly”到“beautiful”的对比。 通过这些知识点,孩子们不仅可以学习到基础的英语语法和词汇,还...
ugly_num.exe
解决ubuntu系统自带的Rthymbox音乐播放器默认不支持mp3和wma格式音乐的播放
标题“Ugly Face”可能指的是一个特殊的字体设计或者一个与字体相关的项目,它以其独特的、可能非传统的美学特征而得名。在这个上下文中,“Ugly Face”可能并不是指实际人脸的丑陋,而是特指一种视觉艺术风格。这种...