Memory limit exceed


  • 0
    H

    string countAndSay(int n){
    if(n==0) return " ";
    if(n==1) return "1";
    string s="1";
    //string ss;
    int i,j;
    int p=0;
    char m;
    string str;
    char c,b;
    for( i=1;i<n;i++)
    {

        for(j=0,m=s[0];j<s.size();j++)
        {
            if(s[j]==m)
            {
                p++;
            }else{
                
                c=m;
                b=48+p;
                str.push_back(b);
                str.push_back(c);
                m=s[j];
                p=1;
            }
        }
        
        c=m;
        b=48+p;
        str.push_back(b);
        str.push_back(c);
        s=str;
        }
        return str;
    }

Log in to reply
 

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