class Solution {
public String countAndSay(int n) {
if (n <= 0) return "-1";
String ans = "1";
for (int i = 1; i < n; i++){
ans = build(ans);
}
return ans;
}
private String build(String str){
StringBuilder sb = new StringBuilder();
int p = 0;
while (p < str.length()){
char c = str.charAt(p);
int count = 0;
while (p < str.length() && str.charAt(p) == c){
count++;
p++;
}
sb.append(String.valueOf(count));
sb.append(c);
}
return sb.toString();
}
}