感觉这个题读题有点费劲啊 。。。。
好像有个正则的方法 我是个菜逼 需要学的有点多,还没看明白,先给自己记个遗留问题~~
class Solution {
public:
string countAndSay(int n) {
if(n == 1) {
return std::to_string(1);
}
string s;
string forward = countAndSay(n - 1);
int flag = 1;
for(int i = 0; i < forward.size() - 1; ++i) {
if(forward[i] == forward[i + 1]) {
flag++;
} else {
s = s + std::to_string(flag) + forward[i];
flag = 1;
}
}
s = s + std::to_string(flag) + forward[forward.size() - 1];
return s;
}
};