[leetcode]264. Ugly Number II
阿新 • • 發佈:2018-12-17
Solution 1: 參照數學質因子的定義,大概規模能跑到800,900,就會超時
我這個方法也太暴力了。
https://blog.csdn.net/fulishafulisha/article/details/79984101
class Solution { public int nthUglyNumber(int n) { int count=0; int i=1; //Ugly numbers are positive numbers while(count<n){ if(help(i,2)) count++; i++; } return i-1; } public boolean help(int i,int k){ while(k<=i){ if(i == k){ return true; } else if(i%k == 0){ i = i/k; } else{ k++; if(k>5)return false; } } return true; } }