class Solution {
public:
string countAndSay(int n)
{
int i=0;
int m=0;
if(n<=0)
return '\0';
string s("1");
stringstream ss;
while(m<n1&&n>1)
{
int i=0;
int len=s.length();
int j=0;
int count=0;
for(;i<len;i++)
{
if(s[i]==s[j])
count++;
else
{
ss<<count;
ss<<s[j];
j=i;
}
}
ss<<count;
ss<<s[j];
s=ss.str();
m++;
}
return s;
}
};
Count and say,output limit exceeded,can you tell me why?thank you!!


Had the same one. It seems the checked first runs all tests and only then compares to expected results. Thus if for some big n the result is not only wrong but also too big it crashes before making the actual comparison.
IMHO a bit unfair, running anc comparing onebyone would let one figure out the actual problem.
Try adding something like:
if (n <= 10)
return string("");To see the actual failure.
Mine was at n=6 :)