思路
暴力解就行了
只需要主要 to_string
string countAndSay(int n) {
string cur="1";
int i=1;
while(i<n){
cur=help(cur);
i++;
}
return cur;
}
string help(string s){
int size=s.size(),count=1;
string res="";
int i=0;
while(i<size){
if(i!=size-1&&s[i]==s[i+1]){
count++;
}else{
res+=to_string(count);
res+=s[i];
count=1;
}
i++;
}
return res;
}
tips
to_string函数将int转为string形式