class Solution {
public String countAndSay(int n) {
if (n == 1)
return "1";
String ans = "1";
for (int i = 2; i <= n; i++) {
ans = next(ans);
}
return ans;
}
private String next(String str) {
// 对字符串str进行描述
char[] chs = str.toCharArray();
StringBuilder descripe = new StringBuilder();
int index = 0;
int count;
char cur;
while (index < chs.length) {
count = 0;
cur = chs[index];
while (index < chs.length && chs[index] == cur) {
++count;
++index;
}
descripe.append(count);
descripe.append(cur);
}
return descripe.toString();
}
}