class Solution {
public:
string countAndSay(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> v;
vector<int> t;
v.push_back(1);
for (int i = 1; i < n; i++) {
t.clear();
for (int pos = 0; pos < v.size(); pos++) {
int count = 1;
while (pos + 1 < v.size() && v[pos] == v[pos + 1]) {
count++;
pos++;
}
t.push_back(count);
t.push_back(v[pos]);
}
v = t;
}
string ret = "";
for (int i = 0; i < v.size(); i++)
ret += v[i] + '0';
return ret;
}
};
Small Case: 8ms
Large Case: 8ms