@@ -0,0 +1,1228 @@
+/***%0A * The count-and-say sequence is the sequence of integers beginning as follows:%0A * 1, 11, 21, 1211, 111221, ...%0A *%0A * 1 is read off as %22one 1%22 or 11.%0A * 11 is read off as %22two 1s%22 or 21.%0A * 21 is read off as %22one 2, then one 1%22 or 1211.%0A * Given an integer n, generate the nth sequence.%0A *%0A * Note: The sequence of integers will be represented as a string.%0A */%0Aimport java.util.StringBuffer;%0A%0Apublic class Solution %7B%0A    // Solution 1, S: O(n%5E2), S: O(n)%0A    public String countAndSay(int n) %7B%0A        StringBuffer s = new StringBuffer(%221%22);%0A        while(--n != 0)%0A            s = getNext(s);%0A        return s.toString();%0A    %7D%0A%0A    private StringBuffer getNext(StringBuffer s) %7B%0A        StringBuffer sb = new StringBuffer();%0A        char counter = '1';%0A        char c = s.charAt(0);%0A        for (int i = 1; i %3C= s.length(); i++) %7B%0A            if (i %3C s.length() && s.charAt(i) == c) %7B%0A                counter++;%0A            %7D else if (i == s.length())%7B%0A                sb.append(counter);%0A                sb.append(c);%0A            %7D else %7B%0A                sb.append(counter);%0A                sb.append(c);%0A                c = s.charAt(i);%0A                counter = '1';%0A            %7D%0A        %7D%0A        return sb;%0A    %7D%0A%7D%0A

add CountandSay.java