| 1 | class Solution { |
| 2 | public String countAndSay(int n) { |
| 3 | |
| 4 | if(n==1) return "1"; |
| 5 | // Recursion |
| 6 | String s=countAndSay(n-1); |
| 7 | StringBuilder res = new StringBuilder(); |
| 8 | // String res=""; |
| 9 | int counter=0; |
| 10 | |
| 11 | for(int i=0;i<s.length();i++) |
| 12 | { |
| 13 | counter++; |
| 14 | // Segregating into groups |
| 15 | if(i==s.length()-1 || s.charAt(i)!=s.charAt(i+1)) |
| 16 | { |
| 17 | res.append(counter).append(s.charAt(i)); |
| 18 | // res=res+counter+s.charAt(i); |
| 19 | counter=0; |
| 20 | } |
| 21 | } |
| 22 | return res.toString(); |
| 23 | |
| 24 | |
| 25 | } |
| 26 | } |
nothing calls this directly
no outgoing calls
no test coverage detected