Output Limit Exceed? Please help


  • 0
    V
    string countAndSay(int n) {
        int itr =0;
        vector <int> s2;
        vector <int> s1;
        s1.push_back(1);
        int count=1;
        int num =0;
        while(n-1){
            itr=0;
            count=1;
            for(int i=0;i<s1.size();i++){
                num = s1[i];
                if(i+1==s1.size()){s2.push_back(count);s2.push_back(num);n--;s1=s2;break;}
                if(num==s1[i+1]){count++;}
                else{s2.push_back(count);s2.push_back(num);count=1;}
            }
        }
        
        std::string actualword;
         char ch;
          for (int i = 0; i < s1.size(); i++) {
          ch = char(s1[i]+'0');
          actualword += ch;
    
     }
        
        return actualword;
    }

Log in to reply
 

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