1、思路:
從1開始遍歷,求出後面每一個轉化後的數。依次求下一個。
string countAndSay(int n) {
string res = "1";
for (int i = 2; i <= n; i++) {
string tempStr;
for (int j = 0; j < res.size(); j++) {
char ch = res[j];
int count = 1;
while (j < res.size() - 1 && ch == res[j + 1]) {
count++;
j++;
}
tempStr.push_back(count + '0');
tempStr.push_back(ch);
}
res = tempStr;
}
return res;
}