Leetcode string
1.Count and Say
class Solution {
public:
string countAndSay(int n)
{
string s1,s2="";
s1="1";
if(n==1)return s1;
for(int i=1;i<n;i++)
{
int j=0;int k=0;
while(j<s1.size())
{
char c=s1[j];
while(s1[j]==c&&j<s1.size())
{
j++;k++;
}
s2+='0'+k;
s2+=c;
k=0;
}
s1=s2;
s2="";
}
return s1;
}
};
错误代码
s2+='0'+k+c;
浙公网安备 33010602011771号