49剑指OFFER之丑数

参考资料:
[1]代码参考 anybody的回答:
https://www.nowcoder.com/profile/5810633/codeBookDetail?submissionId=16629921

[2]代码思路:
https://www.cnblogs.com/lfeng1205/p/6932328.html

即可解决丑数的问题。常规代码时间超时:

//代码运行超时
    int GetUglyNumber_Solution(int index) {
    
        if(index<0)
            return 0;
        int uglyNumberFound = 0;
        int number = 0;
        while(uglyNumberFound 

合格的程序如下:

class Solution {
public:
     int GetUglyNumber_Solution(int index) {
         //步骤0:定义一个丑数集合,怎么确保丑数是排好序的呢?如下。
         if(index<7)
             return index;
         //只能用小括号啊!!!!!
         vector res(index);
         res[0] = 1;
         int t2 = 0,t3 =0,t5 = 0;
         //int i = 1 !!!!
         for(int i=1;i

你可能感兴趣的:(49剑指OFFER之丑数)