原题链接:https://leetcode.com/problems/magical-string/
int magicalString(int n) {
string s = "122";
for (int i = 2, k = 1; i < n; i ++, k = 3 - k ) {
int t = s[i] - '0';
for (int j = 0; j < t; j ++ ) {
s += k + '0';
}
}
int res = 0;
for (int i = 0; i < n; i ++ ) {
if (s[i] == '1') res ++ ;
}
return res;
}