public String countAndSay(int n) {
String arr[] = new String[n + 1];
arr[1] = 1 + "";
for(int i = 2; i <= n ; i++) {
StringBuffer bgf = new StringBuffer("");
char temp = arr[i-1].charAt(0);
int flag = 1 ;
for(int x = 1 ; x < arr[i-1].length();x++) {
if(temp != arr[i-1].charAt(x)) {
bgf.append(flag);
bgf.append(temp);
flag =1;
temp = arr[i-1].charAt(x);
}
else flag++;
}
bgf.append(flag); //妙点
bgf.append(temp);
arr[i] = bgf.toString();
}
return arr[n];
}
}
队列法 也行ok
递归 xxx太难了