package com.fishercoder.solutions;

public class _38 {
/**The count-and-say sequence is the sequence of integers beginning as follows:
 1, 11, 21, 1211, 111221, ...

 1 is read off as "one 1" or 11.
 11 is read off as "two 1s" or 21.
 21 is read off as "one 2, then one 1" or 1211.
 Given an integer n, generate the nth sequence.

 Note: The sequence of integers will be represented as a string.*/
public String countAndSay(int n) {
    StringBuilder curr = new StringBuilder("1");
    StringBuilder prev;
    int count;
    char say;
    for (int i = 1; i < n; i++) {
        prev = curr;
        curr = new StringBuilder();
        count = 1;
        say = prev.charAt(0);

        for (int j = 1, len = prev.length(); j < len; j++) {
            if (prev.charAt(j) != say) {
                curr.append(count).append(say);
                count = 1;
                say = prev.charAt(j);
            } else {
                count++;
            }
        }
        curr.append(count).append(say);
    }
    return curr.toString();
}

}

@@ -33,30 +33,39 @@
 s;%0A%0A
-public class _38 %7B%0A/**
+/**%0A * 38. Count and Say%0A *%0A * 
 The 
@@ -400,16 +400,74 @@
 ring.*/%0A
+%0Apublic class _38 %7B%0A  public static class Solution1 %7B%0A    
 public S
@@ -489,24 +489,26 @@
 ay(int n) %7B%0A
+  
     StringBu
@@ -544,24 +544,26 @@
 r(%221%22);%0A    
+  
 StringBuilde
@@ -574,16 +574,18 @@
 ev;%0A    
+ 
+ 
 int coun
@@ -591,16 +591,18 @@
 nt;%0A    
+  
 char say
@@ -603,16 +603,18 @@
 ar say;%0A
+  
     for 
@@ -817,18 +817,16 @@
         
-  
 if (prev
@@ -842,28 +842,24 @@
 ) != say) %7B%0A
-    
             
@@ -898,28 +898,24 @@
             
-    
 count = 1;%0A 
@@ -921,28 +921,24 @@
             
- 
-   
 say = prev.c
@@ -957,18 +957,16 @@
         
-  
 %7D else %7B
@@ -974,28 +974,24 @@
             
- 
-   
 count++;%0A   
@@ -987,18 +987,16 @@
 ount++;%0A
-  
         
@@ -1049,26 +1049,30 @@
 d(say);%0A    
-%7D%0A
+  %7D%0A  
     return c
@@ -1087,13 +1087,21 @@
 ring();%0A
+    %7D%0A  
 %7D%0A%0A%7D%0A

refactor 38