38. Count and Say
class Solution {
public:
string countAndSay(int n) {
if(n<1)
return "";
string res="1";
for(int i=2;i<=n;i++){
int len=res.size();
string temp;
int index=0;
while(index<len){
int num=1;
char cur=res[index];
while(index<len-1 && res[index]==res[index+1]){
index++;
num++;
}
temp+=to_string(num);
temp+=cur;
index++;
}
res=temp;
}
return res;
}
};