Easy Java Recursive


#1

Comment body goes here.
public class Solution {
public String countAndSay(int A) {
if(A==1){
return “1”;
}
String s=countAndSay(A-1);
int len=s.length();
int i=0;
StringBuilder ans=new StringBuilder();
while(i<len){
char a=s.charAt(i);
i=i+1;
int count=1;
while(i<len && s.charAt(i)==a){
count+=1;
i=i+1;
}
ans.append(count);
ans.append(a);
}
return ans.toString();
}
}