题解 | #丑数#
丑数
https://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b
import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param index int整型
* @return int整型
*/
public int GetUglyNumber_Solution (int index) {
// write code here
int[] res = new int[index];
if(index == 0) return 0;
int i2 = 0, i3 = 0, i5 = 0;
res[0] = 1;
for(int i = 1; i < index; i ++){
res[i] = Math.min(res[i2] * 2, Math.min(res[i3] * 3, res[i5]* 5));
if(res[i] == res[i2] * 2) i2 ++;
if(res[i] == res[i3] * 3) i3 ++;
if(res[i] == res[i5] * 5) i5 ++;
}
return res[index - 1];
}
}



