public String countAndSay(int n) {
        StringBuilder res = new StringBuilder("1");
		for (int i = 2; i <= n; ++i) {
            StringBuilder tmp = new StringBuilder();
			int j = 0;
			while (j < res.length()) {
				int cnt = 1;
				while (j + cnt < res.length() && res.charAt(j) == res.charAt(j + cnt)) {
					++cnt;
				}
				tmp.append(cnt).append(res.charAt(j));
				j += cnt;
			}
			res = tmp;
		}
		return res.toString();
	}