leetcode一道题,count and say,输出有关问题是output limit exceeded
leetcode一道题,count and say,输出问题是output limit exceeded
在VS下运行是没问题的,在leetcode下运行确有问题
代码如下,希望大家帮忙找找,谢谢
------解决方案--------------------
应该 返回 ""
而不是 '\0'
在VS下运行是没问题的,在leetcode下运行确有问题
代码如下,希望大家帮忙找找,谢谢
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<n-1&&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;
}
};
------解决方案--------------------
应该 返回 ""
而不是 '\0'