https://oj.leetcode.com/problems/count-and-say/
求经过n次变换后,变成了什么。
1 11 21 1211 111221
ps. 3 变成 ‘3’,为 3 + '0'
class Solution { public: string countAndSay(int n) { string ans_str; vector<int> input; input.push_back(1); // the first time vector<int> output; for(int i = 1;i<n;i++) { fun(input,output); input = output; } for(int i = 0;i<input.size();i++) ans_str.push_back('0'+input[i]); return ans_str; } void fun(vector<int> input,vector<int> &output) { output.clear(); int itr = 0; while(itr<input.size()) { int value = input[itr]; int times = 0; while(itr<input.size()&&input[itr]==value) { times++; itr++; } output.push_back(times); output.push_back(value); } } };