38.Count and Say
http://blog.csdn.net/xygy8860/article/details/46821417
Understand the Question first.
class Solution {
public String countAndSay(int n) {
if(n == 1){
return "1";
}
// * is used to compare c[i] with c[i + 1];
String str = countAndSay(n - 1) + '*';
char[] c = str.toCharArray();
int cnt = 1;
StringBuilder sb = new StringBuilder();
for(int i = 0; i < c.length - 1; i++){
if(c[i] == c[i + 1]){
cnt++;
}
else{
sb.append(cnt);
sb.append(c[i]);
cnt = 1;
}
}
return sb.toString();
}
}