Advertisement
unknown_0711

Untitled

Dec 19th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. class Solution {
  2. public String countAndSay(int n) {
  3. String output = "1", str = "";
  4. for(int i = 1; i < n; i++, output = str, str= "")
  5. for(int j = 0, count = 1; ; j++)
  6. if(j == output.length() - 1) {
  7. str += String.valueOf(count) + output.charAt(j) ;
  8. break;
  9. }
  10. else if(output.charAt(j) != output.charAt(j + 1)){
  11. str += String.valueOf(count) + output.charAt(j) ;
  12. count = 1;
  13. }
  14. else count++;
  15. return output;
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement