public class Solution { public int GetUglyNumber_Solution(int index) { if (index < 7) return index; // 维护一个对应索引的丑数序列 int[] ans = new int[index]; ans[0] = 1; // 分别用于维护 2, 3, 5 的倍数序列 int t2 = 0, t3 = 0, t5 = 0; for (int i = 1; i < index; i ++) { // 寻找 2, 3, 5 倍数序列的最小值 ans[i] = Math.min(2 * ans[t2], Math.min(3 * ans[t3], 5 * ans[t5])); // 将满足条件的数出队列 if (ans[t2] * 2 == ans[i]) t2 ++; if (ans[t3] * 3 == ans[i]) t3 ++; if (ans[t5] * 5 == ans[i]) t5 ++; } return ans[index - 1]; } }