Leetcode 之Count and Say(35)

时间:2022-08-19 00:31:26

Leetcode 之Count and Say(35)

很有意思的一道题,不好想啊。

string getNext(string &s)
{
char start = s[];
int count = ;
stringstream ss;
for (int i = ; i < s.size(); i++)
{
if (start == s[i])
{
count++;
}
else
{
ss << count << start;
count = ;
start = s[i];
}
}
ss << count << start; return ss.str();
} string countAndSay(int n)
{
string s = "";
for (int i = ; i < n; i++)
s = getNext(s);
}