题解 | #丑数#

丑数

http://www.nowcoder.com/practice/6aa9e04fc3794f68acf8778237ba065b

参考:https://blog.nowcoder.net/n/737d5e8a1f5947eba9446b65ee5f8e84 是真的666

class Solution {
public:
    int GetUglyNumber_Solution(int index) {
        if(index <= 6){
            return index;
        }
        
        int i2=0, i3=0, i5=0;
        vector<int> res(index);
        res[0] = 1;
        
        for(int i=1; i<index; i++){
            res[i] = min(res[i2]*2, min(res[i3]*3, res[i5]*5));
            if(res[i] == res[i2]*2){
                i2++;
            }
            if(res[i] == res[i3]*3){
                i3++;
            }
            if(res[i] == res[i5]*5){
                i5++;
            }
        }
        return res[index-1];
    }
};

全部评论

相关推荐

迷茫的大四🐶:自信一点,我认为你可以拿到50k,低于50k完全配不上你的能力,兄弟,不要被他们骗了,你可以的
点赞 评论 收藏
分享
双非阴暗爬行:我来看看笑死我了,这名字取得好想笑(没有不好的意思)
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务