码迷,mamicode.com
首页 > 其他好文 > 详细

[leetcode] Super Ugly Number

时间:2019-02-01 21:51:42      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:ber   解释   current   class   code   for   i++   tco   nbsp   

用时24ms。

天呐好懒不想写解释先存个草稿放在这里吧……等我找只黄鸭先

class Solution {
public:
    int nthSuperUglyNumber(int n, vector<int>& primes) {
        int ps=primes.size();
        int answer[n], possible_current_answer[ps];
        vector<int> t(ps,0);
        answer[0]=1;
        for (int k=1;k<n;k++) {
            //answer[k]=max{answer[t[i]]*primes[i], i=0:ps-1.}
            for (int i=0;i<ps;i++)
                possible_current_answer[i]=answer[t[i]]*primes[i];
            answer[k]=*min_element(possible_current_answer, possible_current_answer+ps);
            for (int i=0;i<ps;i++) {
                if (answer[k]==possible_current_answer[i])
                    ++t[i];
            }
        }
        return answer[n-1];
    }
};

 

[leetcode] Super Ugly Number

标签:ber   解释   current   class   code   for   i++   tco   nbsp   

原文地址:https://www.cnblogs.com/RDaneelOlivaw/p/10346989.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!