LeetCode 264.丑数II
编写一个程序,找出第 n 个丑数。
丑数就是只包含质因数 2, 3, 5 的正整数。
示例:
输入: n = 10
输出: 12
解释: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 是前 10 个丑数。
说明:
1 是丑数。
n 不超过1690。
class Solution { public: int nthUglyNumber(int n) { vector<int>p; p.push_back(1); int i=0,j=0,k=0; while(--n){ int t=min(p[i]*2,min(p[j]*3,p[k]*5)); p.push_back(t); if(p[i]*2==t)i++; if(p[j]*3==t)j++; if(p[k]*5==t)k++; } //for(auto x:p)cout<<x<<' '; return p.back(); } };