leetcode-华为专题-264. 丑数 II

 

leetcode-华为专题-264. 丑数 II

 

class Solution {
public:
    int nthUglyNumber(int n) {
        int a = 0;
        int b = 0;
        int c = 0;
        vector<int> res(n,1);
        for(int i = 1; i < n; i++){
            int temp = min(res[a]*2,min(res[b]*3,res[c]*5));
            if(temp == res[a]*2)
                a++;
            if(temp == res[b]*3)
                b++;
            if(temp == res[c]*5)
                c++;
            res[i] = temp;
        }
        return res[n-1];
    }
};

 

leetcode-华为专题-264. 丑数 II

上一篇:Vue2.0_基础01


下一篇:map() reduce() filter() 与 forEach()