Time limit exceeded for input 901 on submit but runs in 16ms on custom run?


  • 0
    P
    #include<set> 
    #include<queue>
    #include<algorithm>
    class Solution {
    public:
        int nthUglyNumber(int n) {
            int i=1;
            int count=1;
            set<long long> s;
            //int n;
            //cin>>n;
            s.insert(i);
            std::set<long long>::iterator it;
            for(it=s.begin();count<=20*n;++it){
                s.insert(*it * 2);
                s.insert(*it * 3);
                s.insert(*it * 5);
                count=count+3;
            }
            int j=1;
            for(it=s.begin();it!=s.end();++it){
                //cout<<*it<<endl;
                if(j==n){
                    break;
                }
                j++;
            }
            return *it;
        }
    };`

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.