题目
class Solution {
public String countAndSay(int n) {
String ret = "1";
for(int i=1;i<n;i++)//解释n-1次ret
{
StringBuffer tmp = new StringBuffer();
int len = ret.length();
for(int left = 0,right = 0;right<len;)
{
//双指针
while(right < len && ret.charAt(left) == ret.charAt(right))
right++;
tmp.append(Integer.toString(right - left));//个数
tmp.append(ret.charAt(left));//字符
left = right;
}
ret = tmp.toString();
}
return ret;
}
}