public String countAndSay(int n) {
        String res = "1";
        int i = 1;
        while (i < n) {
            String temp = "";
            char c = res.charAt(0);
            int count = 1, j = 1;
            for (; j < res.length(); ++j) {
                if (c != res.charAt(j)) {
                    temp += Integer.toString(count) + c;
                    c = res.charAt(j);
                    count = 1;
                } else {
                    ++count;
                }
            }
            temp += Integer.toString(count) + c;
            res = temp;
            ++i;
        }
        return res;
    }