首页 > 代码库 > 313. Super Ugly Number
313. Super Ugly Number
17.4.25
WRONG ANSWERS
public class Solution {
public int nthSuperUglyNumber(int n, int[] primes) {
int len = primes.length;
int[] pw = new int[len];//zhizhen
for(int p:pw)
p = 0;
int[] uN = new int[n];//存丑数
for(int u: uN)
u = 0;
//第K个丑数和前K-1个有关
if(n == 1)
return 1;
for (int i = 1; i < n; i++) {
int min = 0;
int[] uNbx = new int[len]; //丑数备选
for (int j = 0; j < len; j++)
uNbx[j] = pw[j] * primes[j];
for(int j = 0; j < len - 1; j++) {//找备选数组最小值
if(uNbx[j] > uNbx[j + 1])
min = uNbx[j + 1];
if (uNbx[j] <= uNbx[j + 1])
min = uNbx[j];
}
for(int j = 0; j < len; j++)
if(min == uNbx[j])
pw[j]++;
}
return uN[n - 1];
}
}
——————————————————————————————————————————————————————————————
313. Super Ugly Number