class Solution {

```
public:
string countAndSay(int n) {
if( n == 1) {
return "1";
}
string prev = countAndSay(n - 1);
string res;
int i = 0, j = 1, len = prev.size();
for(; i < prev.size(); i++) {
if((i == len - 1) || (prev[i] != prev[i + 1])) {
res += (j + '0');
res += prev[i];
j = 1;
} else {
j++;
}
}
return res;
}
```

};