// 简单模拟,对于字符串频繁改动,使用StringBuffer更快
class Solution {
public String countAndSay(int n){
StringBuffer[] str = new StringBuffer[32];
str[1] = new StringBuffer("1");
for (int i = 2; i <= n; i ++){
int len = str[i - 1].length();
int count = 1;
char c = str[i - 1].charAt(0);
str[i] = new StringBuffer("");
for (int j = 1; j < len; j ++){
if (str[i - 1].charAt(j) == c){
count ++;
}else {
str[i].append((char)(count + '0'));
str[i].append(c);
count = 1;
c = str[i - 1].charAt(j);
}
}
str[i].append((char)(count + '0'));
str[i].append(c);
}
return str[n].toString();
}
}