// LeetCode 38 字符串 to_string int to string char 直接变为string
//边界情况 for int i=0 i<.size() 比较的活 i+1 与i 比 i<size -1; 从第二个开始
class Solution {
public:
string countAndSay(int n) {
string res ="1";
string tem = "";
int count =0;
while(--n)
{
tem = res;
res ="";
for(int i=0;i < tem.length();i++)
{
count = 1;
while(i<(tem.length()-1)&&(tem[i+1] == tem[i]) )
{
count++;
i++;
}
res += to_string(count) + tem[i];
}
}
return res;
}
};
51 -leetcode 38 -字符串
最新推荐文章于 2024-05-27 17:03:58 发布