public class Solution { public int GetUglyNumber_Solution(int index) { if(index<=0){ return 0; } int[] p = new int[index]; p[0]=1; int p2=0; int p3=0; int p5=0; int num=1;//索引 while (num < index){ int min = Min(p[p2]*2,p[p3]*3,p[p5]*5); p[num] = min; while(p[p2]*2<=p[num]){ p2++; } while(p[p3]*3<=p[num]){ p3++; } while(p[p5]*5<=p[num]){ p5++; } num++; } int res = p[num-1]; return res; } private static int Min(int i, int j, int k) { int min = i<j ? i : j; min = min < k ? min : k; return min; } }
原文地址:https://www.cnblogs.com/q-1993/p/10878137.html
时间: 2024-10-05 22:19:02